SendTemplate.java 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. package me.zhengjie.config.rabbitmq.test;
  2. import me.zhengjie.config.rabbitmq.cuisine.CuisineConsumer;
  3. import me.zhengjie.config.rabbitmq.cuisine.CuisineProduce;
  4. import me.zhengjie.config.rabbitmq.order.OrderProduce;
  5. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Qualifier;
  8. import org.springframework.stereotype.Component;
  9. @Component
  10. public class SendTemplate {
  11. @Autowired
  12. @Qualifier(CuisineConsumer.TEMPLATE_CON)
  13. private RabbitTemplate rabbitTemplate;
  14. @Autowired
  15. @Qualifier(OrderProduce.TEMPLATE_ORDER)
  16. private RabbitTemplate rabbitTemplate1;
  17. public void sendMessage(Object message){
  18. rabbitTemplate.convertAndSend(CuisineConsumer.NAME, CuisineConsumer.NAME, message.toString());
  19. System.out.println("世贸发送消息----消息发送到rabbitmq");
  20. System.out.println(message);
  21. }
  22. public void sendOrederMessage(Object message){
  23. rabbitTemplate1.convertAndSend(OrderProduce.NAME_ORDER, OrderProduce.NAME_ORDER, message.toString());
  24. System.out.println("雄伟发送消息----消息发送到rabbitmq");
  25. }
  26. }