MessageListenerContainer with MessageHandler?

1.1k views Asked by At

If I use Spring Integration with XML-Configuration, a Message Listener can be done like the following:

<int:channel id="handlerChannel"/>

<bean class="org.springframework.integration.endpoint.EventDrivenConsumer">
    <constructor-arg name="inputChannel" ref="handlerChannel"/>
    <constructor-arg name="handler" ref="alertHandler" />
</bean>

<int-jms:message-driven-channel-adapter channel="handlerChannel" container="listenerContainer" />

<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="prototype">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="defaultDestination"/>
</bean>

The problem is: I want to create own ListenerContainers at the runtime... how I can get the same result or rather how can I combine a MessageHandler with a MessageListenerContainer?

thx and greeting

1

There are 1 answers

5
Gary Russell On BEST ANSWER
MessageChannel channel = new DirectChannel();
DefaultMessageListenerContainer container = ...
JmsMessageDrivenEndpoint inbound = new JmsMessageDrivenEndpoint(container);
inbound.setOutputChannel(channel);
handler.subscribe(channel);
inbound.afterPropertiesSet();
inbound.start();

However, why use Spring Integration at all here; you can wire a MessageListener into the message listener container directly.