简体   繁体   English

兔子mq消息监听器

[英]rabbit mq message listener

Im using 我正在使用

@Autowired
RabbitTemplate temp;
temp.convertAndSend("aQueue", msg);

for sending and 用于发送和

@Autowired
RabbitTemplate temp;
return temp.receiveAndConvert("aQueue");

for receving messages from rappid mq Now I would like to use a listener something like : 从rappid mq接收消息现在,我想使用类似以下的监听器:

@Component

public class MessengerListener implements MessageListener{

    @Override
    public void onMessage(Message arg0) {


    }

}

The problem is that the on onMessage listener works with Messages is it possible to receive simple serializable objects in similar fasion ? 问题是onMessage的onMessage侦听器可以与Messages一起使用,是否有可能以类似的方式接收简单的可序列化对象?

I strongly suggest you do not do this, you should pass XML,JSON(i recommend json),etc. 我强烈建议您不要这样做,您应该传递XML,JSON(我推荐json)等。 to onMessage(..) and unmarshal the responses, not serialized objects over JMS. 到onMessage(..)并解组响应,而不是通过JMS序列化对象。

use something like below for unmarshalling/marshalling the payload 使用以下类似的方法来解组/编组有效负载

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM