Any of these programs will be better than using the MQ sample amqsget.
Capitalware Inc.
Original Message:
Sent: Mon July 31, 2023 04:00 AM
From: Chris Leonard
Subject: MQ plugin/modules for Ansible
I wonder if the queue in question has DEFSOPT(EXCL) in its attributes?
The amqsput utility uses MQOO_INPUT_AS_Q_DEF in its open options (ie. inherit the value of DEFSOPT), whereas MQ Explorer explicitly sets MQOO_INPUT_SHARED when opening a queue to clear it.
If the application specifies MQOO_INPUT_AS_Q_DEF and the queue is configured with DEFSOPT(EXCL), the MQOPEN call will fail if any other processes have the queue open for input. The Python sample you provided also uses MQOO_INPUT_AS_Q_DEF, and so would see the same behaviour in this scenario.
If DEFSOPT(EXCL) is set on your queue, and you're confident that it's not opened exclusively by another process, try using MQOO_INPUT_SHARED by providing explicit open options to amqsget as follows:
amqsget [queue] [queueManager] 8194
(8194 is the decimal value of MQOO_INPUT_SHARED + MQOO_FAIL_IF_QUIESCING)
If opening the queue with an explicit INPUT_SHARED still fails with object in use, that would suggest the other application does have exclusive access to the queue. In that case there's no way to clear the queue underneath that application, other than disconnecting it from the queue manager.
As an alternative, you haven't said why or how often you need to clear the queue. If you're clearing it regularly for housekeeping purposes, you could consider using the CAPEXPRY feature to ensure that un-retrieved messages are expired from the queue after a configured interval. See https://www.ibm.com/docs/en/ibm-mq/9.3?topic=mqmd-enforcing-lower-expiration-times
------------------------------
Chris Leonard
Original Message:
Sent: Sun July 30, 2023 07:33 PM
From: Roger Windberg
Subject: MQ plugin/modules for Ansible
I think the queue is not open in "INPUT_EXCLUSIVE" mode because the process I described in MQ Explorer works fine, it clears the queue. I tried using amqsget but I get an error saying that the queue is already open.
Searching the internet I saw that I can only clear the queue that is already in use by creating an application that uses MQGET API calls to perform this task. I requested AI support to understand how to do this since I don't have much programming knowledge and the suggestion was to create a Python program with the following code:
import pymqiimport CMQCqueue_manager = 'MY_QUEUE_MANAGER'channel = 'SYSTEM.DEF.SVRCONN'host = 'localhost'port = 1414queue_name = 'MY_QUEUE_NAME'qmgr = pymqi.connect(queue_manager, channel, f"{host}({port})")queue = pymqi.Queue(qmgr, queue_name)queue_open_options = CMQC.MQOO_INPUT_AS_Q_DEF | CMQC.MQOO_FAIL_IF_QUIESCINGtry: while True: try: message = queue.get() print("Message cleared: " + message.decode()) except pymqi.MQMIError as e: if e.comp == CMQC.MQCC_FAILED and e.reason == CMQC.MQRC_NO_MSG_AVAILABLE: print("Queue is empty.") break raise efinally: queue.close() qmgr.disconnect()
My question is: Do you think it might work? Is there even a way to remove messages from the queue with it in use?
------------------------------
Roger Windberg
Original Message:
Sent: Fri July 28, 2023 06:32 AM
From: Chris Leonard
Subject: MQ plugin/modules for Ansible
Hi Roger, if you're looking to emulate what MQ Explorer does, you could use the amqsget sample program to destructively get messages from the queue.
https://www.ibm.com/docs/en/ibm-mq/9.3?topic=programs-running-amqsget-amqsgetc-samples
If you want to run the sample program on a different host to the queue manager, you'd need to use the amqsgetc client-mode equivalent program, and configure the MQSERVER environment variable or use a CCDT file to provide details of the queue manager's SVRCONN channel to use as described in the link above.
The content of each message consumed will be output to stdout, so you can redirect to /dev/null if you have no interest in the message data itself (although it may be helpful to keep an amount of audit log of the messages removed, depending on the scenario).
It's also worth noting that this approach won't work if another application already has the queue open for INPUT_EXCLUSIVE (the same is true of the MQ Explorer approach you've described).
------------------------------
Chris Leonard
Original Message:
Sent: Wed July 26, 2023 11:32 PM
From: Roger Windberg
Subject: MQ plugin/modules for Ansible
Hey guys!
Is there any way to clear a queue that is currently in use with Ansible? In my company, sometimes we need to access the Windows server, run "IBM MQ Explorer", access the Queue Manager, select the queue, run "Clear Messages..." and check "Clear with MQGET API calls". This process is a bit time consuming and I'm trying to do it remotely with Ansible.
I looked a lot about this and the only way I saw was to create an application to use MQGET API to accomplish this task. I don't have the knowledge in Java application development, C#/C++ and etc to create this, so I thought there might be something ready to do this task in Ansible.
------------------------------
Roger Windberg
Original Message:
Sent: Thu January 19, 2023 06:44 AM
From: James Page
Subject: MQ plugin/modules for Ansible
Hello Renato,
Further to this, the MQ-Ansible project is now external on github.com below:
https://github.com/ibm-messaging/mq-ansible
Please feel free to get in touch if you have any further questions.
Kind Regards,
James Page
------------------------------
James Page
Original Message:
Sent: Tue January 10, 2023 06:33 AM
From: James Page
Subject: MQ plugin/modules for Ansible
Hello Renato,
Following on from #7 by Fabio Nuzzi, the MQ-Ansible project is soon to be externalised (NB: the exact timing is undecided at the moment). So far, we have implemented the following, which is tested on the Ubuntu OS:
- Ansible Roles to fully automate MQ installation process, and Web Console setup.
- Ansible module 'queue_manager', which allows:
- Defining and Controlling QMGRs (Create/Start/Stop/Delete)
- Running MQSC for basic configuration
(e.g in your case, MQ-Ansible would replace the use of the separate 'shell' and 'command' modules with just the 'queue_manager' module.
Future features will be added in the coming months.
I hope this helps!
Kind Regards,
James Page
------------------------------
James Page
Original Message:
Sent: Tue July 21, 2020 10:38 AM
From: Renato Zancoper
Subject: MQ plugin/modules for Ansible
Is there any focus on the development of an MQ plugin/modules for Ansible?
It is known that Ansible is being adopted by larger enterprises to automate maintenances and/or repetitive tasks, and there are a large number of MQ admin tasks that could benefit from that.
Nowadays, when we want to automate something related to MQ, we depend on shell scripts to call MQ commands (strmqm, endmqm, etc) or run MQSC script thru runmqsc.
For example, having automation in Ansible, to call a shell script, which will call runmqsc, to run an MQSC command to suspend a QM from a cluster, before stopping the QM does not sound an elegant solution!
------------------------------
Renato Zancoper
DataPower & MQ Admin
IBM
------------------------------