1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| @Component public class Producer {
@Resource("springboot.queue.a") private Queue queuea;
@Resource("springboot.queue.b") private Queue queueb;
@Resource("springboot.topic") private Topic topic;
@Resource("springboot.queuereply") private Queue queuereply;
@Autowired private JmsMessagingTemplate jmsTemplate;
public void sendMessage(Destination destination, final String message){ jmsTemplate.convertAndSend(destination, message); }
public void sendQueueAMessage(final String message){ sendMessage(queuea, message); }
public void sendQueueBMessage(final String message){ sendMessage(queueb, message); }
public void sendTopicMessage(final String message){ sendMessage(topic, message); }
public void sendQueueMessageReply(final String message){ sendMessage(queuereply, message); }
@JmsListener(destination = "out.replyTo.queue") public void consumerMessage(String text){ System.out.println("从out.replyTo.queue收到报文"+text); } }
|