3 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超4個(gè)贊
message.getBody()是您所需要的 - 它將返回byte[],您需要在知道您正在使用的消息格式的情況下對(duì)其進(jìn)行轉(zhuǎn)換:
@RabbitListener(queues = SECOND_QUEUE)
public void onMessage(Message message) {
byte[] body = message.getBody();
// do what you need with the body
}

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以像這樣獲取數(shù)據(jù):
@Override
public void onMessage(Message message, byte[] pattern) {
yourmap.put("data", message);
send();
}
然后,
String s = yourmap.get("data").toString();
您可以從流中獲取已發(fā)布的數(shù)據(jù)。
我希望這將有所幫助。

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
這對(duì)我有用
@RabbitListener(queues = SECOND_QUEUE)
public void onMessage(Message message) {
LOGGER.info("second queue listener.........");
//LOGGER.info(message.toString());
byte[] body = message.getBody();
LOGGER.info("This was the output from the listener "+new String(body));
}
添加回答
舉報(bào)