Spring:如何使用注释配置Messaging Bridge轮询器

时间:2017-05-17 05:50:54

标签: java spring spring-mvc spring-integration spring-messaging

我希望能够限制从SubscribableChannel收到的请求。我不使用PollableChannel。我是否能够做到这一点:

<bridge input-channel="pollable" output-channel="subscribable">
     <poller max-messages-per-poll="10">
         <interval-trigger interval="5" time-unit="SECONDS"/>
     </poller>
 </bridge>

http://docs.spring.io/spring-integration/docs/2.0.0.M4/spring-integration-reference/html/bridge.html

使用注释?

2 个答案:

答案 0 :(得分:1)

有点晚了,但这是我在用例中找到的解决方案:

<int-amqp:inbound-channel-adapter id="inbound-channel" prefetch-count="100"  concurrent-consumers="1" connection-factory="connectionFactory" queue-names="${queue.name}" error-channel="error-channel" />

<int:json-to-object-transformer input-channel="inbound-channel" output-channel="queue-channel" />

<int:channel id="queue-channel">
    <int:queue capacity="100" />
</int:channel>

<int:bridge input-channel="queue-channel" output-channel="outbound-channel">
    <int:poller max-messages-per-poll="100" fixed-delay="1000" />
</int:bridge>

<int:outbound-channel-adapter id="outbound-channel" ref="myServiceBean" method="onMessage" />

说明:

amqp入站通道适配器是可订阅的。 A使用&#34;队列样式切换到可轮询频道&#34;通道并使用网桥执行从队列通道到出站通道的轮询。

在我的情况下,我应该配置一个消息存储或将我的amqp入站通道适配器的确认模式设置为手动,并自行执行以避免丢失我的消息。

此致

答案 1 :(得分:0)

使用桥接处理程序......

@Bean
@ServiceActivator(inputChannel = "polled", 
        poller = @Poller(fixedRate = "5000", maxMessagesPerPoll = "10"))
public BridgeHandler bridge() {
    BridgeHandler bridge = new BridgeHandler();
    bridge.setOutputChannelName("direct");
    return bridge;
}

......或者只是......

@Bean
@BridgeTo(value = "direct", poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "10"))
public PollableChannel polled() {
    return new QueueChannel();
}

@Bean
public SubscribableChannel direct() {
    return new DirectChannel();
}

@Bean
public PollableChannel polled() {
    return new QueueChannel();
}

@Bean
@BridgeFrom(value = "polled", poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "10"))
public SubscribableChannel direct() {
    return new DirectChannel();
}
相关问题