springboot集成rabbitmq

@Component
@RabbitListener(queues = "hello")
public class HelloReceiver {

    @RabbitHandler
    public void process(String hello) {
        System.out.println("Receiver  : " + hello);
    }

}

@Component
public class HelloSender {
@Autowired
private AmqpTemplate template;
public void send(){
String context = “hello ” + new Date();
System.out.println(“Sender : ” + context);
this.template.convertAndSend(“hello”, context);
}
}

@Configuration
public class RabbitConfig {
    @Bean
    public Queue Queue() {
        return new Queue("hello");
    }
}

spring.application.name=spirng-boot-rabbitmq

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
“`
參考博客:https://www.cnblogs.com/ityouknow/
項目地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章