久久久久久久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:獲取當前星期幾的值)
主站蜘蛛池模板: 日本午夜在线视频 | 手机在线观看av | 亚洲精品99久久久久久 | 人成精品 | 国产精品一区一区三区 | 91av精品| 亚洲福利片| 在线观看中文字幕av | 亚洲欧洲成人在线 | 天天射网站 | 日韩中文欧美 | 一区二区三区日 | 色橹橹欧美在线观看视频高清 | 亚洲高清视频一区二区 | 国产视频在线观看一区二区三区 | 国产黄色在线观看 | 国产sm主人调教女m视频 | av毛片在线免费观看 | 丁香婷婷综合激情五月色 | 天天射色综合 | 国产精品久久久久久久午夜片 | 久久在线免费 | 嫩草网| 国产成人99久久亚洲综合精品 | 四虎在线观看 | 亚洲视频在线一区 | 久久99精品久久久久久秒播九色 | 国产精品欧美一区二区三区不卡 | 国产精品久久久乱弄 | 五月激情婷婷在线 | 97精品国产97久久久久久免费 | 成人欧美一区二区三区黑人孕妇 | 免费a国产 | 91麻豆精品国产91久久久久久 | 欧美va大片 | 九九视频网 | 婷婷国产一区二区三区 | 四虎影院新网址 | 国产日韩久久久久69影院 | 精品无码久久久久久国产 | 欧美精品一区二区三区在线播放 |