久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

僅使用 RabbitMQ 和 SpringAMQP 使用具有某些標頭的消

Only consuming messages with certain headers using RabbitMQ and SpringAMQP(僅使用 RabbitMQ 和 SpringAMQP 使用具有某些標頭的消息)
本文介紹了僅使用 RabbitMQ 和 SpringAMQP 使用具有某些標頭的消息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試將消息發布到隊列,然后只有當它包含某個標頭時才讓某些消費者使用它,如果它包含另一個標頭,另一個消費者會使用它.

I'm trying to publish a message to a queue and then have certain consumers consume it only if it contains a certain header and another consumer consume it if it contains another header.

到目前為止,我所做的是設置一個標頭交換,僅當消息包含該標頭時才將消息路由到某個隊列.

What I've done so far is to setup a headers-exchange that routes messages to a certain queue only if it contains that header.

這是我用來設置交換、隊列和監聽器的配置:

This is the config I'm using to setup the exchange and the queue and the listener:

<!-- Register Queue Listener Beans -->
<bean id="ActionMessageListener" class="com.mycee.Action" />    

<!-- Register RabbitMQ Connections -->
<rabbit:connection-factory 
    id="connectionFactory"
    port="${rabbit.port}"
    virtual-host="${rabbit.virtual}" 
    host="${rabbit.host}" 
    username="${rabbit.username}"
    password="${rabbit.password}" 
    connection-factory="nativeConnectionFactory" />

<!-- Register RabbitMQ Listeners -->
<rabbit:listener-container          
    connection-factory="connectionFactory"
    channel-transacted="true"
    requeue-rejected="true"
    concurrency="${rabbit.consumers}">
    <rabbit:listener queues="${queue.myqueue}" ref="ActionMessageListener" method="handle"/>        
</rabbit:listener-container>    

<!-- Setup RabbitMQ headers exchange -->
<rabbit:headers-exchange id="${exchange.myexchange}" name="${exchange.myexchange}">
    <rabbit:bindings>
        <rabbit:binding queue="${queue.myqueue}" key="action" value="action3" />            
    </rabbit:bindings>
</rabbit:headers-exchange>

<rabbit:admin connection-factory="connectionFactory"/>  
<rabbit:queue name="${queue.myqueue}" />

所以我使用 action 的鍵和 action3 的值將 myqueue 綁定到 myexchange.

So I'm binding myqueue to myexchange using key of action and value of action3.

現在當我在交易所發布時:

Now when I publish on the exchange:

即使操作設置為 action1 而不是 action3,ChannelAwareMessageListener 仍在使用它

the ChannelAwareMessageListener is consuming it even though the action was set to action1 instead of action3

public class Action implements ChannelAwareMessageListener {

    @Override
    public void onMessage(Message message, Channel channel) throws Exception {

        System.out.println(message.toString());

    }

}

要么我沒有正確使用 headers-exchange,要么我沒有正確配置它 - 有什么建議嗎?

Either I'm not using a headers-exchange correctly or I'm not configuring it correctly - any advice ?

推薦答案

這樣不行;每個消費者都需要一個單獨的隊列.請參閱教程.

It doesn't work that way; you need a separate queue for each consumer. See the tutorial.

當多個消費者從同一個隊列消費時,他們會競爭所有消息;您不能在消費者端選擇消息;選擇"是由交換機通過將消息路由到特定隊列來完成的.

When multiple consumers consume from the same queue they compete for all messages; you can't select messages on the consumer side; the "selection" is done by the exchange by routing messages to specific queue(s).

這篇關于僅使用 RabbitMQ 和 SpringAMQP 使用具有某些標頭的消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 久久99精品久久久久久 | 久久久一区二区三区 | 免费在线视频精品 | 福利视频网站 | 日韩av在线一区 | 欧美 日韩 国产 成人 在线 | 亚洲成人av在线播放 | 国产精品五月天 | 精品视频一区二区三区 | 国产精品1区2区3区 欧美 中文字幕 | 在线免费观看欧美 | 99久久久久久 | 涩涩视频在线观看 | 国产免费一区二区三区最新6 | 欧美v在线观看 | 欧美性猛交一区二区三区精品 | 亚洲影视在线 | 高清视频一区二区三区 | 综合中文字幕 | 久久伊人影院 | 日韩中文字幕在线视频观看 | 婷婷午夜天 | 亚洲国产精品久久久久婷婷老年 | 一区二区精品 | 国产不卡一区在线观看 | 国产在线观看网站 | 日韩中出| 色视频一区二区 | 中文在线a在线 | 国产成人免费视频网站高清观看视频 | 福利视频一区二区 | 一区二区三区中文字幕 | 精品毛片 | 欧美日韩电影免费观看 | 999精品网| 一二三区视频 | 无毛av | 就操在线| 国产精品一区二区三区久久久 | 久久久观看 | 九九看片 |