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

將消息從 RabbitMQ 轉換為字符串/json

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

問題描述

限時送ChatGPT賬號..

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

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();
    }

}

和消息監聽器

public class PageQueueListener implements MessageListener {

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

我的問題是,getBody() 方法顯示 [B@4dbb73b0 所以沒有任何東西被轉換.既不是字符串也不是 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));

這篇關于將消息從 RabbitMQ 轉換為字符串/json的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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| 久久99蜜桃综合影院免费观看 | 久久精品二区 | 伊人二区 | 人人看人人爽 | 91资源在线| 免费国产视频 | 第一福利社区1024 | 亚洲综合无码一区二区 | 久草新视频 | 日本高清视频在线播放 | 99久久婷婷 | 色吊丝2288sds中文字幕 | 亚洲成人毛片 | 亚洲精品一区中文字幕乱码 | 蜜桃黄网 | gogo肉体亚洲高清在线视 | 色综合久久久 | 日韩精品在线看 | 国产最好的av国产大片 | 人人玩人人干 | 久久精品91久久久久久再现 | 日本一区二区高清不卡 | 免费成人国产 | 久久青视频| 日韩成人av在线播放 | 羞羞色影院 | 伊人伊人伊人 | 国产精品一区二区免费看 | 成人国产网站 | 亚洲精品乱码久久久久久按摩 | 天天干天天爽 | 日本中文字幕日韩精品免费 | 盗摄精品av一区二区三区 | 国产区在线视频 |