@RabbitListener
时间: 2023-12-07 11:05:46 浏览: 27
@RabbitListener is an annotation used in Spring Boot framework to listen to messages from RabbitMQ. It is a part of the Spring AMQP (Advanced Message Queuing Protocol) project, which provides abstraction over the messaging protocols.
By using @RabbitListener annotation, we can consume messages from a specific queue or topic in RabbitMQ. We can also specify the exchange type, routing key, and the container factory to configure the message listener.
Here's an example of using @RabbitListener annotation in Spring Boot:
```
@RabbitListener(queues = "myqueue")
public void receiveMessage(String message) {
System.out.println("Received message: " + message);
}
```
In the above example, the method annotated with @RabbitListener will listen to messages from the "myqueue" queue in RabbitMQ. Whenever a message is received, the method will be called with the message payload as the method parameter.