簡體   English   中英

Spring Integration-設置發送消息的上限

[英]Spring Integration - setting upper limit on sending messages

我正在寫一個回復傳入消息的郵件服務,我想設置一個限制-每小時最多發送10條消息。 它也應該在全時重置。

Spring Integration中可能嗎? 我在Spring文檔中閱讀了有關任務計划的信息,但不確定是否與我的情況相符。 我想我可以設置一個CronTrigger以固定的速率發送消息,但這聽起來並不像我真正想要實現的那樣。

提前致謝。

我想你雖然走對了。

您配置一個QeueueChannelPollingConsumer@ServiceActivator@Poller )。 您絕對可以在那里進行cron觸發:

/**
 * @return The cron expression to create the {@link CronTrigger}.
 * Can be specified as 'property placeholder', e.g. {@code ${poller.cron}}.
 */
String cron() default "";

您可以通過以下方式達到max 10 sent messages/hour要求:

/**
 * @return The maximum number of messages to receive for each poll.
 * Can be specified as 'property placeholder', e.g. {@code ${poller.maxMessagesPerPoll}}.
 * Defaults to -1 (infinity) for polling consumers and 1 for polling inbound channel adapters.
 */
String maxMessagesPerPoll() default "";

所以,當通過根據設置cron時間調度執行的任務,僅配置maxMessagesPerPoll將從拉QeueueChannel和用於處理(發送電子郵件)向下游發送。

https://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/messaging-channels-section.html#polling-consumer中查看更多信息,並尋找“ Important: Poller Configuration段。

暫無
暫無

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

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