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

Spring AMQP 集成 - 消費者手冊 致謝

Spring AMQP Integration - Consumer Manual Acknowledgement(Spring AMQP 集成 - 消費者手冊 致謝)
本文介紹了Spring AMQP 集成 - 消費者手冊 致謝的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在測試 Spring-AMQPSpring-Integration 支持,我有以下配置和測試:

I am testing Spring-AMQP with Spring-Integration support, I've following configuration and test:

<rabbit:connection-factory id="connectionFactory" />
<rabbit:queue name="durableQ"/>
<int:channel id="consumingChannel">
    <int:queue capacity="2"/> <!-- Message get Acked as-soon-as filled in Q -->
</int:channel>

<int-amqp:inbound-channel-adapter 
    channel="consumingChannel"
    queue-names="durableQ" 
    connection-factory="connectionFactory"
    concurrent-consumers="1"
    acknowledge-mode="AUTO"
    />


public static void main(String[] args) {
System.out.println("Starting consumer with integration..");
    AbstractApplicationContext context = new ClassPathXmlApplicationContext(
    "classpath:META-INF/spring/integration/spring-integration-context-consumer.xml");

    PollableChannel consumingChannel = context.getBean("consumingChannel",   
                                                          PollableChannel.class);           
        int count = 0;
        while (true) {
            Message<?> msg = consumingChannel.receive(1000);
            System.out.println((count++) + " 	 -> " + msg);

            try { //sleep to check number of messages in queue
                Thread.sleep(50000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

在此配置中,很明顯,一旦消息到達 sumptionChannel,它們就會被確認并因此從隊列中刪除.我通過在 receive 之后放置一個高 sleep 并檢查 queue-size 來驗證這一點.沒有進一步的控制.

In this configuration it was evident that as soon as message arrives at consumingChannel they are Acked and hence removed from queue. I validated this by placing a high sleep after receive and check queue-size. There are no further control on it.

現在,如果我設置 acknowledge-mode=MANUAL,似乎沒有辦法通過 spring 集成手動執行 ack.

Now if I set acknowledge-mode=MANUAL, there are no ways seems to do manual ack via spring integration.

我需要處理消息,并在處理后執行 manual-ack,以便 ack 消息保持在 durableQ 處.

My need is to process message and after processing do a manual-ack so till ack message remains persisted at durableQ.

有沒有辦法用 spring-amqp-integration 處理 MANUAL ack?我想避免將 ChannelAwareMessageListener 傳遞給 inbound-channel-adapter,因為我想控制消費者的 receive.

Is there any way to handle MANUAL ack with spring-amqp-integration? I want to avoid passing ChannelAwareMessageListener to inbound-channel-adapter since I want to have control of consumer's receive.

更新:

當使用自己的 listener-containerinbound-channel-adapter 時,這似乎是不可能的:

It even doesn't seems to be possible when using own listener-container with inbound-channel-adapter:

// Below creates a default direct-channel (spring-integration channel) named "adapter", to receive poll this channel which is same as above
<int-amqp:inbound-channel-adapter id="adapter" listener-container="amqpListenerContainer" /> 

<bean id="amqpListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="queueNames" value="durableQ" />
    <property name="acknowledgeMode" value="MANUAL" />

// messageListener not allowed when using with adapter, so no way of having own ChannelAwareMessageListener, so no channel exposed onMessage, hence no way to ack
    <property name="messageListener" ref="listener"/>
</bean>
<bean id="listener" class="com.sd.springint.rmq.MsgListener"/>

上述配置拋出錯誤,因為 messageListener 屬性是不允許的,請參閱標記的內聯注釋.所以使用 listner-container 的目的被打敗了(通過 ChannelAwareMessageListener 暴露 channel).

Above configuration throws error as messageListener property is not allowed, see inline comment on tag. So purpose of using listner-container got defeated (for exposing channel via ChannelAwareMessageListener).

對我來說 spring-integration 不能用于 manual-acknowledgement (我知道,這很難說!),任何人都可以幫我驗證這個或者是我缺少任何特定的方法/配置嗎?

To me spring-integration cannot be used for manual-acknowledgement (I know, this is a hard saying!), Can anyone help me in validating this or Is there any specific approach/configuration required for this which I am missing?

推薦答案

問題是因為您使用的是使用 QueueChannel 的異步切換.通常最好控制容器中的并發性(concurrent-consumers="2"),并且不要在流程中進行任何異步切換(使用 DirectChannels).這樣,AUTO ack 就可以正常工作了.而不是從 PollableChannel 接收 new MessageHandler()SubscribableChannel.

The problem is because you are using async handoff using a QueueChannel. It is generally better to control the concurrency in the container (concurrent-consumers="2") and don't do any async handoffs in your flow (use DirectChannels). That way, AUTO ack will work just fine. Instead of receiving from the PollableChannel subscribe a new MessageHandler() to a SubscribableChannel.

更新:

您通常不需要在 SI 應用程序中處理消息,但您使用 DirectChannel 進行的測試相當于...

You normally don't need to deal with Messages in an SI application, but the equivalent of your test with a DirectChannel would be...

    SubscribableChannel channel = context.getBean("fromRabbit", SubscribableChannel.class);

    channel.subscribe(new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            System.out.println("Got " + message);
        }
    });

這篇關于Spring AMQP 集成 - 消費者手冊 致謝的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 成年网站在线观看 | 91精品久久久久久久久久 | 99精品视频免费观看 | 中文字幕亚洲视频 | 91福利网 | 在线观看你懂的网站 | a国产一区二区免费入口 | 日本高清视频在线播放 | 黄色在线观看国产 | www.黄色在线观看 | 亚洲精品美女 | 久久69精品久久久久久久电影好 | 国产精品久久久久久影视 | 五月天婷婷综合 | 污免费网站 | 欧美日韩福利视频 | 精品国产三级 | 成人午夜在线 | h视频在线观看免费 | 精品在线播放 | 亚洲成人精选 | 99免费在线观看视频 | 亚洲精品成人在线 | 操操操av | www.狠狠干 | 先锋资源亚洲 | 国产毛片久久久久久久久春天 | 日韩在线欧美 | 久久久精| 精品国产欧美一区二区 | 精品国产精品三级精品av网址 | 亚洲一区二区三区四区五区午夜 | 亚洲一区中文字幕 | 亚洲成人激情在线观看 | 91亚洲国产 | 国产免费色 | 成人乱人乱一区二区三区软件 | 中文字幕在线视频免费观看 | 国产婷婷综合 | 欧美成视频 | 亚洲美女天堂网 |