简体   繁体   中英

What is the id of the listener container when using Spring's JMS namespace?

According to the Spring Documentation for the JMS Namespace tags (ie <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?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM