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

將消息從 RabbitMQ 轉(zhuǎn)換為字符串/json

Converting Message from RabbitMQ into string/json(將消息從 RabbitMQ 轉(zhuǎn)換為字符串/json)
本文介紹了將消息從 RabbitMQ 轉(zhuǎn)換為字符串/json的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我目前正在努力解決一個相當(dāng)簡單的問題.我想從 RabbitMQ 接收消息并將其轉(zhuǎn)換為字符串(或稍后轉(zhuǎn)換為 json 對象).但我得到的只是字節(jié).

I am currently struggling hard with a fair simple problem. I want to receive a message from RabbitMQ and have that transformed into a string (or later a json object). But all I get is bytes.

Message 對象以這種方式將自身顯示為字符串

The Message object displays itself as a string that way

(Body:'{"cityId":644}'; ID:null; Content:application/json; Headers:{}; Exchange:; RoutingKey:pages.type.index; Reply:null; DeliveryMode:NON_PERSISTENT; DeliveryTag:1)

配置類(使用spring)

The configuration class (using spring)

@Configuration
public class RabbitConfiguration {

    @Bean
    public CachingConnectionFactory connectionFactory() {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory("www.example.com");
        connectionFactory.setUsername("xxxx");
        connectionFactory.setPassword("xxxx");
        return connectionFactory;
    }

    @Bean
    public MessageConverter jsonMessageConverter(){
        JsonMessageConverter jsonMessageConverter = new JsonMessageConverter();
        return jsonMessageConverter;
    }

    @Bean
    public SimpleMessageListenerContainer messageListenerContainer(){
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory());
        container.setAutoStartup(false);
        container.setQueues(indexQueue());
        container.setConcurrentConsumers(1);
        container.setAcknowledgeMode(AcknowledgeMode.AUTO);
        container.setMessageListener(new MessageListenerAdapter(pageListener(), jsonMessageConverter()));
        return container;
    }

    @Bean
    public Queue indexQueue(){
        return new Queue("pages.type.index");
    }

    @Bean
    public MessageListener pageListener(){
        return new PageQueueListener();
    }

}

和消息監(jiān)聽器

public class PageQueueListener implements MessageListener {

    public void onMessage(Message message) {
        System.out.println(message);
        System.out.println(message.getBody());
    }
 }

我的問題是,getBody() 方法顯示 [B@4dbb73b0 所以沒有任何東西被轉(zhuǎn)換.既不是字符串也不是 json 對象:(

my problem is, that the getBody() method displayes [B@4dbb73b0 so nothing is ever converted. Neither to a string nor to a json object :(

我覺得自己很愚蠢,但我在這里找不到解決方案

I feel stupid, but I cannot find a solution here

推薦答案

message.getBody() 返回一個byte[]

試試:

byte[] body = message.getBody();
System.out.println(new String(body));

這篇關(guān)于將消息從 RabbitMQ 轉(zhuǎn)換為字符串/json的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
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 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 国产精品久久av | 99免费视频 | 午夜免费视频观看 | 91亚洲国产成人精品一区二三 | 亚洲精品在线免费观看视频 | 91久久精品一区二区二区 | 久精品久久 | 日韩乱码一二三 | 国产一区二区a | 欧美一区二区黄 | 91av在线不卡| 精品视频一区在线 | 国产欧美一区二区三区久久手机版 | 一区二区精品 | 国产wwwcom | 久久久久久久久久久高潮一区二区 | 成人不卡 | 91精品国产色综合久久 | 国产一级片 | 国产成人网 | a在线视频| 精品欧美色视频网站在线观看 | 91xxx在线观看 | 一区二区精品 | 黄色免费在线观看网站 | 欧美精品一二三 | 一区二区三区视频在线 | 久久精品国产99国产精品 | 激情在线视频 | 精品国产精品国产偷麻豆 | 91精品久久久久 | 色播av| 羞羞网站免费观看 | 龙珠z在线观看 | 日韩中文字幕在线不卡 | 在线免费观看视频你懂的 | 手机在线观看 | 欧洲成人午夜免费大片 | 亚洲视频免费观看 | 日韩成人在线播放 | 国产视频在线一区二区 |