SpringCloud分布式微服务b2b2c电子商务(十三)Springboot整合RabbitMQ

  

  

  

  

     

  

  

  

  

  

  

  

  

  

  

  

  
  

酿造安装rabbitmq

  

安装完成后开启服务器:

  
  rabbitmq服务器

  

开启服务器成功,你可以看到以下信息:

  <>以前brew  install  rabbitmq   安装完成后开启服务器:   rabbitmq服务器   开启服务器成功,你可以看到以下信息:   

     
  

  
 & lt; dependency>
  ,,,,,,,,,,,& lt; groupId> org.springframework.boot
  ,,,,,,,,,,,& lt; artifactId> spring-boot-starter-amqp
  ,,,,,,,& lt;/dependency> 
  

     
        

  
 @ component
  public  class  Receiver  {
  ,,,private  CountDownLatch  latch =, new  CountDownLatch (1);
  ,,,public  void  receiveMessage (String 消息),{
  ,,,,,,,System.out.println (“Received  & lt;“, +, message  +,“在“);
  ,,,,,,,latch.countDown ();
  ,,,}
  ,,,public  CountDownLatch  getLatch (), {
  ,,,,,,,return 插销;
  ,,,}
  }
  

  

     

  

  

  

     

  

  

  

  

  

  

  

  <>以前package  com.forezp;   import  com.forezp.message.Receiver;   import  org.springframework.amqp.core.Binding;   import  org.springframework.amqp.core.BindingBuilder;   import  org.springframework.amqp.core.Queue;   import  org.springframework.amqp.core.TopicExchange;   import  org.springframework.amqp.rabbit.connection.ConnectionFactory;   import  org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;   import  org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;   import  org.springframework.boot.SpringApplication;   import  org.springframework.boot.autoconfigure.SpringBootApplication;   import  org.springframework.context.annotation.Bean;   @SpringBootApplication   public  class  SpringbootRabbitmqApplication  {   ,,,,final  static  String  queueName =,“spring-boot";   ,,@ bean   ,,,Queue 队列(),{   ,,,,,,,return  new 队列(queueName,,假);   ,,,}   ,,@ bean   ,,,TopicExchange 交换(),{   ,,,,,,,return  new  TopicExchange (“spring-boot-exchange");   ,,,}   ,,@ bean   ,,,Binding 绑定(Queue 队列,TopicExchange 交换),{   ,,,,,,,return  BindingBuilder.bind(队列),(交换);(queueName);   ,,,}   ,,@ bean   ,,,SimpleMessageListenerContainer 容器(ConnectionFactory  connectionFactory,   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,MessageListenerAdapter  listenerAdapter), {   ,,,,,,,SimpleMessageListenerContainer  container =, new  SimpleMessageListenerContainer ();   ,,,,,,,container.setConnectionFactory (connectionFactory);   ,,,,,,,container.setQueueNames (queueName);   ,,,,,,,container.setMessageListener (listenerAdapter);   ,,,,,,,return 集装箱;   ,,,}   ,,@ bean   ,,,MessageListenerAdapter  listenerAdapter (Receiver 接收机),{   ,,,,,,,return  new  MessageListenerAdapter(接收机,“receiveMessage");   ,,,}   ,,,public  static  void  main (String [], args), {   ,,,,,,,SpringApplication.run (SpringbootRabbitmqApplication.class, args);   ,,,}   }

SpringCloud分布式微服务b2b2c电子商务(十三)Springboot整合RabbitMQ