user12277274
user12277274

Reputation: 109

Is there a way to restrict the messages consumed from the IBM MQ in mule 4

I have a requirement, where I am publishing data to the IBM MQ and at around 10pm we run a scheduler that should consume only those messages that are published before 10pm. The messages that are published on or after 10pm should be picked next day.

Is there a way in IBM MQ where we can filter it based on the datetime and consume? Any suggestion?

Thanks in advance.

Upvotes: 0

Views: 609

Answers (2)

Morag Hughson
Morag Hughson

Reputation: 7525

What you'd really like to be able to do is use a message selector something like this:-

Root.MQMD.PutDate = '20210924' AND Root.MQMD.PutTime < '22000000'

However, unfortunately, the only operators you are allowed to use with strings (and both of these fields are string fields) are = and <> (not-equals) (see IBM MQ Docs: Message selector syntax).

Alternatively, you could make use of QLOAD which can select messages based on time, and have it pre-process the queue by moving all the messages you should be processing to another queue and then allow your application to work on that entire queue. You could invoke QLOAD to do this as follows:-

qload -m QM1 -i INPUT.Q -Tt22:00 -o APPL.INPUT.Q

This command will read messages from a queue called INPUT.Q and will only move those that were put today before 22:00 (10pm) to the queue called APPL.INPUT.Q.

Of course, QLOAD is not doing anything here that you couldn't write into your own application. Just inspect the PutDate and PutTime fields in the MQMD and use those to decide whether to process the message or not.

Upvotes: 2

aled
aled

Reputation: 25699

You can try to use a selector expression in the listener to filter by time.

This is an example adapted from the documentation on how to use a selector expression:

<flow name="JMSConnectorPublish">
  <jms:listener config-ref="JMS_Config" destination="in" selector="JMSPriority=9"/> 
</flow>

It doesn't use the time. You'll need to be familiar with the headers and attributes from IBM MQ/JMS messages to find the right expression. Probably attributes.headers.JMSTimestamp is going to be of interest to you.

Upvotes: 0

Related Questions