Converting Message from RabbitMQ into string/json

前端 未结 2 1632
傲寒
傲寒 2021-01-12 02:44

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 al

相关标签:
2条回答
  • 2021-01-12 03:01

    If you want to parse to a JSONObject, the best way is add the RabbitMQ message to a StringBuilder in String format. Then parse the StringBuilder into a JSONObject, by using any of the conversion utils.
    For e.g.:

    StringBuilder sb = new StringBuilder();
    sb.append(publisher.toString());
    payload = (JSONObject)jsonParser.parse(sb.toString());
    
    0 讨论(0)
  • 2021-01-12 03:05

    message.getBody() returns a byte[]

    Try:

    byte[] body = message.getBody();
    System.out.println(new String(body));
    
    0 讨论(0)
提交回复
热议问题