我需要将我的json有效负载放入Rabbitmq并从队列中接收消息。我可以向队列发送消息,但是当我尝试从主题交流中检索消息时,我得到了空指针异常。在onMessage方法实现中的下一行抛出空指针异常。
simpleMessage=(SimpleMessage) rabbitTemplate.receiveAndConvert(qu);
有人可以解释我该怎么做,还是可以引导我找到具有解决方案的链接
@Component
public class RabbitListener implements me {
@Autowired
RabbitTemplate rabbitTemplae;
//@Override
public void onMessage(Message message) {
System.out.println("in listener");
SimpleMessage simpleMessage= new SimpleMessage();
// System.out.println("Received a new message = [" + new String(message.getBody().toString()) + "]");
System.out.println("READY TO RECEIVE");
String qu=message.getMessageProperties().getConsumerQueue();
System.out.println("que name "+qu);
//simpleMessage=(SimpleMessage) rabbitTemplae.receiveAndConvert("MyTestQueue");
//System.out.println("rabbitMQ RECEIVE MESSAGE "+ rabbitTemplae.receiveAndConvert("MyTestQueu", 100000));
simpleMessage=(SimpleMessage) rabbitTemplae.receiveAndConvert(qu);
//rabbitTemplae.receiveAndConvert
// System.out.println( simpleMessage.getDescription());
}
}
需要将其从队列转换回以下对象
public class SimpleMessage implements Serializable {
private String name;
private String description;
public SimpleMessage() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "SimpleMessage{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
'}';
}
}