我正在尝试将 spring 批处理的输出发送到 RabbitMQ。为了避免对 Rabbitmq 的硬依赖,我按照在 spring-xd中是否有 API 来写入消息总线中的建议使用了 spring-integration ?. 我在将消息推送到 RabbitMQ 时一切正常,直到我决定通过 Spring 自动装配或实例化 bean。
<context:component-scan base-package="com.test.*"/>
<channel id="input" />
<rabbit:connection-factory id="connectionFactory" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
exchange="testExchange" routing-key="foo.bar" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="testQueue" id="timeseriesQueue" />
<rabbit:topic-exchange name="testExchange"
id="testExchange">
<rabbit:bindings>
<rabbit:binding queue="testQueue" pattern="foo.*" />
</rabbit:bindings>
</rabbit:topic-exchange>
<!-- Send message to rabbitmq -->
<gateway id="testGateway"
service-interface="com.test.TestService"
default-request-channel="input" />
<amqp:outbound-channel-adapter channel="input"
amqp-template="amqpTemplate" exchange-name="testExchange"
routing-key="foo.bar" />
Run Code Online (Sandbox Code Playgroud)
testService 只是一个带有方法 sendMessage 的接口。
spring 批处理作业有一个 itemWriter,它使用网关 bean 写入 RabbitMQ …