Question

According to the Spring Documentation for the JMS Namespace tags (i.e. <jms:listener-container>), there is no id attribute for a <jms:listener-container> element.

How do I reference the listener container bean from other bean definitions if there is no id for it?

For example, say I have the following Listener container defined:

<jms:listener-container acknowledge="auto"
    connection-factory="queueConnectionFactoryBean"
    container-type="default"
    destination-resolver="jndiDestinationResolver"
    destination-type="queue"
    message-converter="myConverter">

    <jms:listener ref="myListenerPOJO" id="myQueueListener"
        method="processThePOJO" destination="${myQueueListener.queue.jndiName}" />

</jms:listener-container>

And I want to define an inbound gateway that uses the above container. What would I use as the container property for the inbound gateway definition?

Example:

<int-jms:inbound-gateway 
    request-channel="inboundChannel"
    id="messageChannelAdapter"
    container="**What Goes Here?**"
    reply-channel="outboundChannel" />

Or am I misunderstanding the relationship between listener container and gateway?

Was it helpful?

Solution

The listener-container element isn't meant for configuring a standalone JMS listener container. It is meant to act as a blueprint for all enclosed listener tags. What, at runtime, actually happens is that a JMS Listener Container is constructed for each enclosed listener. So there is not a single container but multiple.

As @artembilan mentioned the id of the container is set to the id of the listener. However when you would reuse the listener for spring integration it would render the listener useless. A listener-container can only have a single MessageListener attached, not multiple.

If you want to use a listener container for a Spring Integration gateway you will have to construct one yourself using one of the *MessageListenerContainer classes.

OTHER TIPS

As Marten said, listener-container pupolates the MessageListenerContainer beans for each listener sub-element. And what is magic the target MessageListenerContainer gets the id from the listener's id.

So, in your case the <int-jms:inbound-gateway>'s container should apply the value myQueueListener.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top