MessageListenerContainer与MessageHandler?

时间:2014-12-01 14:32:51

标签: spring spring-integration spring-jms spring-messaging

如果我使用Spring-Integration with XML-Configuration,可以像下面这样完成Message Listener:

<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>

问题是:我想在运行时创建自己的ListenerContainers ...如何获得相同的结果,或者我如何将MessageHandler与MessageListenerContainer结合起来?

thx和问候

1 个答案:

答案 0 :(得分:0)

MessageChannel channel = new DirectChannel();
DefaultMessageListenerContainer container = ...
JmsMessageDrivenEndpoint inbound = new JmsMessageDrivenEndpoint(container);
inbound.setOutputChannel(channel);
handler.subscribe(channel);
inbound.afterPropertiesSet();
inbound.start();

但是,为什么要在这里使用Spring Integration;您可以直接将MessageListener连接到消息侦听器容器中。