如果我不想使用dsl编写构建jms和spring集成通道之间连接的代码,它是如何做的

问题描述 投票:0回答:1

在此链接中,作者使用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

spring-integration spring-batch
1个回答
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

更多关于JmsSendingMessageHandlerhttps://docs.spring.io/spring-integration/docs/current/reference/html/jms.html#jms-outbound-channel-adapter

© www.soinside.com 2019 - 2024. All rights reserved.