@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/
项目地址