簡體   English   中英

Spring Integration和RabbitMQ,如何避免對入站通道適配器進行輪詢

[英]Spring Integration and RabbitMQ, how can I avoid polling on my inbound channel adapter

我目前有一個可以直接交換的Rabbit MQ Broker設置,並且我正在使用Spring Integration從隊列中生成和使用消息。 我使用的是責任鏈模式,其中我使用SI將消耗的消息從一個POJO傳遞到另一個POJO。 現在,我使用了Spring Integration入站通道適配器。 這要求它具有對輪詢器的引用。

我該如何刪除輪詢程序,以便它不能在輪詢機制上工作,而是使用回調,以便一旦有消息可用,它將從隊列中提取它,同時仍然能夠使用SI提供的責任鏈模式。

我試圖將inboud通道適配器更改為Spring Rabbit入站通道適配器,但是無法將消息轉發到我的POJO。 不支持以下內容。

ref="eventConsumer" method="onReceiveEvent"

我在下面定義了一些簡單的配置,如何在無需輪詢的情況下實現同一目的?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int="http://www.springframework.org/schema/integration"
    xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
                        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <import resource="classpath:datasource-config.xml" />

    <int:logging-channel-adapter id="logger" level="DEBUG" log-full-message="true" />

    <int:channel id="eventChannel">
        <int:interceptors>
            <int:wire-tap channel="logger" />
        </int:interceptors>
    </int:channel>

    <int:channel id="errorChannel">
        <int:interceptors>
            <int:wire-tap channel="logger" />
        </int:interceptors>
    </int:channel>

    <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
        <property name="host" value="${rabbitmq.host}" />
        <property name="port" value="${rabbitmq.port}" />
        <property name="username" value="${rabbitmq.username}" />
        <property name="password" value="${rabbitmq.password}" />
        <property name="virtualHost" value="${rabbitmq.events.virtual.host}" />
    </bean>

    <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
        <constructor-arg name="connectionFactory" ref="connectionFactory" />
        <property name="exchange" value="${rabbitmq.events.exchange.name}" />
        <property name="routingKey" value="${rabbitmq.events.routing.key}" />
    </bean>

    <bean id="pollingInterval" class="java.lang.String">
        <constructor-arg value="${rabbitmq.message.polling.interval}" />
    </bean>

    <int:poller id="rabbitConsumerPoller" fixed-rate="#{pollingInterval}" error-channel="errorChannel" />

    <bean id="eventConsumer" class="com.idna.events.consumer.EventsConsumer">
        <property name="rabbitTemplate" ref="rabbitTemplate"/>
        <property name="consumerDao" ref="eventsConsumerDao" />
        <property name="queueName" value="${rabbitmq.events.queue.name}" />
    </bean>

    <int:inbound-channel-adapter id="inboundChannelAdapter" channel="eventChannel" ref="eventConsumer" method="onReceiveEvent">
        <int:poller ref="rabbitConsumerPoller"/>
    </int:inbound-channel-adapter>

</beans>

謝謝!

使用<int-amqp:inbound-channel-adapter />將消息發送到eventChannel。 您的消費者不需要了解兔子。 可以通過<service-activator />調用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM