Spring: How to configure Messaging Bridge poller with annotations

╄→尐↘猪︶ㄣ 提交于 2020-01-07 05:37:07

问题


I want to be able to throttle requests received from my SubscribableChannel. I do not use a PollableChannel. Will i be able to do an equivalent of this:

<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

using annotations?


回答1:


With a bridge handler...

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

...or simply...

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

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

or

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

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



回答2:


A little late but here is a solution I found for my use case :

<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" />

Explanation :

amqp inbound channel adapter is subscribable. A do the switch to a pollable channel using the "queue style" channel and use a bridge to perform a polling from the queue-channel to the outbound-channel.

In my case I should configure a message-store or set the acknowledge-mode of my amqp inbound channel adapter to manual and do the ack my self to avoid losing my messages.

Regards



来源:https://stackoverflow.com/questions/44016599/spring-how-to-configure-messaging-bridge-poller-with-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!