Search code examples
muleibm-mqdataweavemulesoft

How to perform a health Check for an IBM MQ Publish operation in Mule


I have a requirement where I need to perform a healthCheck for an IBM Publish operation. Currently we are posting all the messages with no issues. But, I'm looking for an other way to perform kind of healthcheck on the queue in case sometimes the queue is down. I will be able to notify the source to stop sending message continuously. Is there any kind of rest call where from Mule we can achieve this or any other work around to be considered.


Solution

  • You could perform a publish in a transaction, and then rollback the transaction. Use a Try scope with the transactionalAction="ALWAYS_BEGIN" and then raise a magic error to make it roll back. That way the message does not actually become available to the consumers of the queue or topic.

    Here is one way to do it:

        <flow name="healthcheckFlow">
            <try doc:name="Outside try to capture the error after the transaction is rolled back">
                <try doc:name="Inside try to provide the transaction" transactionalAction="ALWAYS_BEGIN">
                  <ibm-mq:publish config-ref="IBM_MQ_Config" destination="importantQueue"/>
                    <raise-error type="APP:ROLLBACK" description="this error is only raised to cause the transaction to roll back" />
                    <error-handler>
                        <on-error-propagate logException="false" type="APP:ROLLBACK">
                            <logger level="DEBUG" message="Health check successful, rolling back transaction" category="example"/>
                        </on-error-propagate>
                    </error-handler>
                </try>
                <error-handler >
                    <on-error-continue logException="false" type="APP:ROLLBACK"/>
                </error-handler>
            </try>
            <logger level="INFO" message="Health check OK" category="example"/>
        </flow>