【问题标题】:How to configure simple RabbitMQ message producer with Spring Integration如何使用 Spring Integration 配置简单的 RabbitMQ 消息生产者
【发布时间】:2015-02-25 18:45:06
【问题描述】:

我想使用 Spring Integration 构造配置一个简单的 RabbitMQ 消息生成器。要求是非常基本的:只是一个简单的即发即弃,将事件消息发送到队列,不需要响应。 我已经配置了连接工厂、RabbitTemplate 和出站通道适配器(见下文),但缺少最后一部分:实际将消息发送到通道的代码。 提前致谢。

<rabbit:connection-factory id="producerRabbitConnectionFactory" 
        channel-cache-size="${amqp.channel.cache.size}"
        host="${amqp.hostname}"
        port="${amqp.port}" 
        virtual-host="${amqp.vhost}" 
        username="${amqp.username}"
        password="${amqp.password}"
        requested-heartbeat="${amqp.heartbeat}"
/>

<bean id="producerRabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
        <property name="connectionFactory" ref="producerRabbitConnectionFactory" />
        <property name="exchange" value="${amqp.exchange.event}" />
        <property name="routingKey" value="${amqp.routingKey.event}" />
</bean>

<int:channel id="outboundAmqpChannel" />

<int-amqp:outbound-channel-adapter id="outboundAmqpChannelAdapter"
                               channel="outboundAmqpChannel"
                               amqp-template="producerRabbitTemplate"
                               default-delivery-mode="NON_PERSISTENT"
                               lazy-connect="true"/>

【问题讨论】:

    标签: rabbitmq spring-integration amqp


    【解决方案1】:

    最简单的是Messaging Gateway。这样一来,您的代码就不会知道您与集成流的对话。

    public interface Foo {
    
        void bar(String foo);
    
    }
    
    <int:gateway service-interface="foo.Foo" default-request-channel="outboundAmqpChannel" />
    

    Foo 注入您的代码并调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      相关资源
      最近更新 更多