如果我不想使用dsl编写在jms和spring集成通道之间建立连接的代码,该怎么做

时间:2019-02-13 05:30:41

标签: spring-integration spring-batch

在此链接中,作者使用特定于Java域的语言来建立从Spring集成通道到activeMQ的连接。如果我不想使用java dsl,而只想使用一般的java方法。我该怎么办?

@Bean
public IntegrationFlow outboundFlow(ActiveMQConnectionFactory connectionFactory) {
    return IntegrationFlows
            .from(requests())
            .handle(Jms.outboundAdapter(connectionFactory).destination("requests"))
            .get();
}

https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/java/org/springframework/batch/sample/remotepartitioning/aggregating/WorkerConfiguration.java

1 个答案:

答案 0 :(得分:2)

Jms.outboundAdapter(connectionFactory)JmsSendingMessageHandler周围的语法糖包装。

.handle()@ServiceActivator等效。

因此,纯Java需要的是这样的:

@Bean
@ServiceActivator(inputChannel="requests")
public MessageHandler jmsMessageHandler((ActiveMQConnectionFactory connectionFactory) {
   JmsSendingMessageHandler handler = new JmsSendingMessageHandler(new JmsTemplate(connectionFactory));
   handler.setDestinationName("requests");
   return handler;
}

请参阅文档中的一些说明:https://docs.spring.io/spring-integration/docs/current/reference/html/overview.html#programming-tips

有关JmsSendingMessageHandler的更多信息:https://docs.spring.io/spring-integration/docs/current/reference/html/jms.html#jms-outbound-channel-adapter