2014-12-01 3 views
1

는 메시지 리스너 같이 수행 할 수 있습니다 다음MessageHandler가있는 MessageListenerContainer? 내가 XML-구성으로 봄의 통합을 사용하는 경우

<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를 결합 할 수 있습니까?

들으 및 인사말

답변

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

그러나, 왜 전혀 여기에 봄 통합을 사용; MessageListener을 메시지 수신기 컨테이너에 직접 연결할 수 있습니다.

+0

고마워, 게리 ... :) 나는 자신의 메시지 객체에'Message '-Interface를 사용한다. 'getHeaders()'메소드는 헤더 정보를 bean 프라퍼티에 매핑하는 데 매우 사용하기 쉽기 때문에 Spring Integration'@ Publisher'에 하나의 메시지 객체를 사용할 수 있고 리스너에는 같은 객체를 사용할 수 있습니다. 헤더 정보를 설정하는 위치는 오직 하나뿐입니다. Spring Integration'@ Publisher'는 정말 멋지고 짧지 만'Message ' objects를 원합니다. – Smoothi

+0

아, 그래; 시원한. 이것이 귀하의 질문에 대한 답변이라면, 다른 사람들이 답변을 구하는 것을 돕기 위해 대답을 '수락하는'것이 습관적입니다. –

+0

당신의 솔루션을 시도했지만'JmsMessageDrivenEndpoint'는 컨테이너와'ChannelPublishingJmsMessageListener'를 필요로합니다. 'setOutboundChannel()'메소드는'JmsMessageDrivenEndpoint'에 대해 정의되지 않았으며 핸들러 인터페이스에는'subscribe()'메소드가 없습니다. 어쩌면'JmsMessageDrivenEndpoint'가 올바른 클래스가 아니겠습니까? – Smoothi