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

spring amqp rabbitmq MessageListener 不工作

spring amqp rabbitmq MessageListener not working(spring amqp rabbitmq MessageListener 不工作)
本文介紹了spring amqp rabbitmq MessageListener 不工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試使用 spring amqp 使用rabbitmq,下面是我的配置.

I am trying to use rabbitmq using spring amqp, below is my configuration.

<rabbit:connection-factory id="rabbitConnectionFactory"
    port="${rabbitmq.port}" host="${rabbitmq.host}" />

<rabbit:admin connection-factory="rabbitConnectionFactory" />

<rabbit:queue name="${rabbitmq.import.queue}" />

<rabbit:template id="importAmqpTemplate"
    connection-factory="rabbitConnectionFactory" queue="${rabbitmq.import.queue}" />

<beans:bean id="importExchangeMessageListener"
    class="com.stockopedia.batch.foundation.ImportMessageListener" />

<rabbit:listener-container
    connection-factory="rabbitConnectionFactory" concurrency="5">
    <rabbit:listener queues="${rabbitmq.import.queue}" ref="importMessageListener" />
</rabbit:listener-container>

這是一個簡單的消息監聽類,

This is simple Message Listener class,

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class ImportMessageListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        System.out.println("consumer output: " + message);
    }

}

這是producer(即spring batch的itemWriter),

This is producer (which is itemWriter of spring batch),

public class ImportItemWriter<T> implements ItemWriter<T> {

    private AmqpTemplate template;

    public AmqpTemplate getTemplate() {
        return template;
    }

    public void setTemplate(AmqpTemplate template) {
        this.template = template;
    }

    public void write(List<? extends T> items) throws Exception {
        for (T item : items) {
            Object reply = template.convertSendAndReceive(item.toString());
            System.out.println("producer output: " + reply);
        }
    }

}

當我運行我的 spring 批處理作業時, ImportItemWriter.write 被調用.但是 ImportMessageListener.onMessage 不起作用.它不打印消息.我得到控制臺上所有項目的低于輸出

When I run my spring batch job, ImportItemWriter.write gets called. But ImportMessageListener.onMessage does not work. It doesnt print the message. I get below output for all items on console

producer output: null
producer output: null
producer output: null
producer output: null
producer output: null
producer output: null
producer output: null

推薦答案

您的消費者沒有發送結果...

Your consumer is not sending a result...

@Override
public void onMessage(Message message) {
    System.out.println("consumer output: " + message);
}

改成簡單的POJO;容器的 MessageListenerAdapter 將為您處理轉換,并發送結果.

Change it to a simple POJO; the container's MessageListenerAdapter will take care of the conversion for you, and send the result.

@Override
public String handleMessage(String message) {
    System.out.println("consumer output: " + message);
    return "result";
}

您還沒有設置任何交換或路由到您的隊列.如果您想使用默認交換/路由,請使用...

You also haven't set up any exchange or routing to your queue. If you want to use default exchange/routing, use...

convertSendAndReceive("", queueName, item.toString());

或者,將模板上的 routingKey 設置為隊列名稱,然后可以使用更簡單的方法.

Or, set the routingKey on the template to the queue name and then you can use the simpler method.

...sendAndReceive() 方法適用于請求/回復場景,因此需要阻塞.要異步執行此操作,您必須使用 ...send() 方法之一,并連接您自己的 SimpleListenerContainer 以接收回復;你將不得不做你自己的相關性.使用

The ...sendAndReceive() methods are meant for request/reply scenarios so blocking is required. To do it asynchronously, you have to use one of the ...send() methods, and wire up your own SimpleListenerContainer to receive the replies; you will have to do your own correlation. Use

public void convertAndSend(Object message, MessagePostProcessor postProcessor)

在您的消息后處理器中,設置 replyTocorrelationId 標頭...

and in your message post processor, set the replyTo and correlationId headers...

message.getMessageProperties().setReplyTo("foo");
message.getMessageProperties().setCorrelationId("bar");

或者,自己構建 Message 對象(例如 通過使用 MessageBuilder) 并使用 send 方法...

Or, build the Message object yourself (e.g by using the MessageBuilder) and use the send method...

template.send(MessageBuilder.withBody("foo".getBytes())
            .setReplyTo("bar")
            .setCorrelationId("baz".getBytes())
            .build());

每個請求都需要一個唯一的 correlationId,以便您可以關聯響應.

Each request needs a unique correlationId so you can correlate the response.

這篇關于spring amqp rabbitmq MessageListener 不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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:獲取當前星期幾的值)
主站蜘蛛池模板: 日韩福利 | 日韩激情网 | 久久性色| 亚洲69p | 亚洲 欧美 激情 另类 校园 | 免费亚洲网站 | 国产在线精品一区二区 | 91视频在线看 | 久久久2o19精品 | 国产有码| 欧美日韩综合 | 在线第一页 | 亚洲成人在线网 | 美女黄网站 | 亚洲精品久久 | 久久免费视频在线 | 精品91久久 | 亚洲天堂一区二区 | 亚洲精品第一国产综合野 | 九色av| 毛片入口| 国产69久久精品成人看动漫 | 看av片网站 | 久久综合伊人一区二区三 | 亚洲欧美一区二区三区视频 | 免费黄色网址视频 | 91九色在线观看 | 久草在线免费资源 | 国产乱码精品1区2区3区 | 久久精品欧美视频 | 国产一区二区三区久久 | 一区二区三区福利视频 | 国产精品成人久久久久 | 丝袜久久| 日韩伦理一区二区 | 日韩在线播放第一页 | a在线观看 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 久久精品亚洲国产 | 欧美成人a∨高清免费观看 老司机午夜性大片 | 亚洲国产一区二区三区在线观看 |