0
votes

I have a requirement to fetch jms message from IBM MQ. But the messages should be fetched only when required, say when a method is invoked. The picked up message need to be put to another queue in turn. That is , this scenario is for copying message from one queue to another when required.

How could I achieve this in Spring Integration.

I believe i could create a flow using inbound-channel-adapter, set to poll message at regular interval, along with outbound-channel-adapter. But with this, I could not pick the message as and when required.

Please advise.

Question updated:

1) While searching on the web to implement the suggested solution, I stepped on the spring documentation for JmsDestinationPollingSource saying - "This source is only recommended for very low message volume".

2) Since we need for high volume environment and in need of local transaction, I looked into the suggested JmsMessageDrivenEndpoint solution which looked like using MessageDrivenChannelAdapter. Can you please adviseas how i could proceed.

3) Also, in that case how can i detect if all messages have been read to stop the listener . Please advise

Question updated:

I am able to invoke start and stop on DefaultMessageListener container used with MessageDrivenChannelAdapter.

Can you also please advise as how I could find when there are no messages on the queue or when the queue is empty so that I could invoke stop.

Question updated:

Thanks Gary. Sorry for the late update.

To find when the queue becomes empty, can we override noMessageReceived method of DefaultMessageListenerContainer (inherited from AbstractPollingMessageListenerContainer) and invoke stop on the DMLC. This kind of solution is given in Spring integration inbound-gateway Fire an event when queue is empty.

I thought this might be easier to implement. Please advise if it will be correct to do in that way.

1

1 Answers

1
votes

Set auto-startup="false" on the inbound channel adapter (so it won't poll).

Get a reference to its MessageSource (either by @Autowire or otherwise injecting or context.getBean()). The bean name is adapterid.source and is of type JmsDestinationPollingSource.

Then invoke the receive() method.

Or you can just wire up a JmsDestinationPollingSource bean yourself without using the namespace support.