rabbitMQ报警推送简单方法

  • application.yml配置
spring:
   rabbitMQ:
      host:125.25.23
      port:5672
      userName:dfwfwd
      password:635623
      
  • maven配置
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
  • 队列配置
@Configuration
public class RabbitConfig {
 
    @Bean
    public Queue helloQueue() {
        return new Queue("hello");
    }
}
  • 发送者:

@Component
public class HelloSend {
    
    @Autowired
    private AmqpTemplate rabbitTemplate;

    public void send(){
        String message = "hello "+new Date();
        logger.info("message:"+message);
        rabbitTemplate.convertAndSend("hello",message);
        logger.info("队列发送成功");
    }
}
  • 接受者:

@Component
@RabbitListener(queues = "hello")
public class HelloReceiver {
    @RabbitHandler
    public void process(String hello) {
        System.out.println("Receiver  : " + hello);
    }
}

猜你喜欢

转载自blog.csdn.net/ty0903csdn/article/details/85040472