如何将ActiveMQ队列与Spring Integration一起使用



我有一个本地ActiveMQ服务器,我想使用Spring Integration轮询名为"test"的队列中的消息。

在我轮询了消息之后,我想把它发送到另一个频道,该频道会把它写在文件系统中的文本文件上。

我看到了一些使用的例子

<int-jms:message-driven-channel-adapter id="jmsIn" destination="inQueue" channel="exampleChannel"/>

我想使用Java注释创建这个JMS"轮询器"。我找不到任何关于如何将上面的XML内容替换为注释的参考。有人能提供一个工作片段,让连接工厂配置和jms:message驱动的通道适配器完成注释吗?

附言:这是一个具有XML配置的参考

https://examples.javacodegeeks.com/enterprise-java/spring/integration/spring-boot-integration-activemq-example/

提前感谢!

好吧,对于正确的Java&使用Spring Integration Java DSL需要考虑的注释配置。

以下是<int-jms:message-driven-channel-adapter>等价物的一些示例:

@Bean
public IntegrationFlow jmsMessageDrivenRedeliveryFlow() {
return IntegrationFlows
.from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory())
.errorChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)
.destination("jmsMessageDrivenRedelivery")
.configureListenerContainer(c -> c
.transactionManager(mock(PlatformTransactionManager.class))
.id("jmsMessageDrivenRedeliveryFlowContainer")))
.<String, String>transform(p -> {
throw new RuntimeException("intentional");
})
.get();
}

要写入文件,您需要使用Files.outboundAdapter():https://docs.spring.io/spring-integration/docs/5.0.6.RELEASE/reference/html/files.html#_configuring_with_the_java_dsl_9

我同意我们缺少JMS部分的类似文档,所以请随时就此事提出JIRA。

最新更新