1

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

Smoothi
  • 283
  • 1
  • 3
  • 15

1 Answers1

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

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • thank you, Gary... :) I use the `Message`-Interface for own message objects. The `getHeaders()` method is very easy to use to map header information to bean properties, so I can use one message object for the Spring Integration `@Publisher` and the same object for the listeners. There is only one location to set header informations. The Spring Integration `@Publisher` is really nice and short, but wants `Message` objects :) – Smoothi Dec 01 '14 at 16:14
  • Ah, ok; cool. If this answers your question, it is customary to 'accept' the answer, to help other people seeking answers. – Gary Russell Dec 01 '14 at 16:25
  • I tried your solution, but the `JmsMessageDrivenEndpoint` needs the container AND a `ChannelPublishingJmsMessageListener`. The `setOutboundChannel()` method is undefined for the `JmsMessageDrivenEndpoint` and the handler interface has no `subscribe()` method. Maybe, the `JmsMessageDrivenEndpoint` isn't the correct class? – Smoothi Dec 02 '14 at 07:03
  • Ok, you meant `channel.subsribe(handler)`, but I believe the JmsMessageDrivenEndpoint is not correct :) – Smoothi Dec 02 '14 at 07:28
  • Sorry, you are correct; it also needs a `ChannelPublishingJmsMessageListener` and __it__ gets the channel via `setRequestChannel`. – Gary Russell Dec 02 '14 at 14:29