亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

RabbitMQ延遲接收

RabbitMQ延遲接收

HUH函數 2023-03-02 16:38:12
是否有可能以某種方式推遲 spring-amqp 中某個特定隊列的監聽消息?在我的用例中,我有一個服務必須監聽兩個 RabbitMQ 隊列上的消息。第一個專用于此服務,第二個用于我服務的多個實例(在不同機器上運行)的負載平衡作業。我在 statup 上的服務通過第一個隊列接收配置并自行配置。只有在該配置之后,才允許處理來自第二個隊列的“標準”作業——而不是之前。我怎樣才能做到這一點?使用 @RabbitListener(queues = {queue1,queue2}) 立即開始收聽。我也看過 rabbitmq_delayed_message_exchange,但這不是我想要的,因為它延遲了消息的處理。我不想延遲處理(其他已經配置的消費者可以處理工作)。感謝您的任何幫助。
查看完整描述

1 回答

?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

有@RabbitListener一個autoStartup選項:


/**

 * Set to true or false, to override the default setting in the container factory.

 * @return true to auto start, false to not auto start.

 * @since 2.0

 */

String autoStartup() default "";

我想你最好有兩個單獨的@RabbitListeners:一個用于配置隊列,另一個用于非自動啟動。配置準備就緒后,您需要從中獲取第二個容器的容器RabbitListenerEndpointRegistry.getListenerContainer()并調用其start(). 你id也可以在那一秒配置@RabbitListener:


/**

 * The unique identifier of the container managing for this endpoint.

 * <p>If none is specified an auto-generated one is provided.

 * @return the {@code id} for the container managing for this endpoint.

 * @see org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry#getListenerContainer(String)

 */

String id() default "";

有關詳細信息,請參閱文檔:https://docs.spring.io/spring-amqp/docs/2.1.7.RELEASE/reference/html/#async-annotation-driven


查看完整回答
反對 回復 2023-03-02
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號