【发布时间】:2016-05-08 08:25:30
【问题描述】:
我使用 spring 大约一年了,在我遇到 spring 集成之前,一切都非常明显和简单。很惭愧,我无法创建出站网关来将消息发送到远程 JMS (ActiveMQ) 通道。在集成之前我只是直接使用了JmsTemplates和@JmsListeners,完全没有问题。
-
request-destination和request-channel有什么区别? -
这是我的配置:
@Configuration @EnableJms public class JmsConfig { ... @Value("${activemq.url}") private String brokerUrl; @Bean public JmsTemplate jmsTemplate() { JmsTemplate jmsTemplate = new JmsTemplate(queueConnectionFactory()); jmsTemplate.setDefaultDestinationName(bookingChannelName); return jmsTemplate; } /* @Bean(name = "bookingChannel") public Queue activeMQQueue() { return new ActiveMQQueue(bookingChannelName); } */ @Bean public JmsListenerContainerFactory jmsListenerContainerFactory() { SimpleJmsListenerContainerFactory listenerFactory = new SimpleJmsListenerContainerFactory(); listenerFactory.setConnectionFactory(queueConnectionFactory()); return listenerFactory; } ...}
还有一个 xml 文件,我在根
beans元素中得到的所有内容是:<jms:outbound-gateway request-destination-name="reqDestination" request-channel="bookingChannel" />然后,有一个网关代码:
@MessagingGateway public interface BookingGateway<T> { @Gateway void bookTicket(T ticket); }最后,这是我使用网关的方法:
@Component public class BookingGatewayImpl<T> { @Autowired private BookingGateway bookingGateway; public <U> void bookTicket(T ticket, BiConsumer<T, U> onStatusReceived) { bookingGateway.bookTicket(ticket); // second param is not utilized yet } }
当机票即将被预订时,我得到:
send is not supported, because no request channel has been configured
另外,我无法从第一个清单中取消注释 ActiveMQQueue bean,因为 spring 说它与 MessageChannel 不兼容:
Bean named 'bookingChannel' must be of type [org.springframework.messaging.MessageChannel], but was actually of type [org.apache.activemq.command.ActiveMQQueue]
为什么目的地应该是MessageChannel 类型?我到底做错了什么以及如何发送此票消息?
【问题讨论】:
标签: java spring jms activemq spring-integration