dawdler-client-plug-rabbitmq
Module introduction
Implements injection of the RabbitProvider and RabbitListener annotations on the web side.
1. Add the dependency to the pom
<groupId>club.dawdler</groupId>
<artifactId>dawdler-client-plug-rabbitmq</artifactId>
2. Usage
Sender: simply annotate a field of type RabbitProvider with @RabbitInjector.
Consumer: annotate a consumer method with @RabbitListener; the method parameter is of type Message.
@Controller
public class UserController{
@RabbitInjector("myRabbitmq")//myRabbitmq is the name of the configuration file, without the properties suffix
RabbitProvider rabbitProvider;
@RequestMapping(value = "/pushMessage", method = RequestMethod.POST)
public void pushMessage(String message) {
rabbitProvider.publish("", "test", null, message.getBytes());//use the rabbitProvider object
}
@RabbitListener(fileName = "myRabbitmq", queueName = "test") //listen to the test queue
public void consumer(Message message) {
System.out.println(new String(message.getBody()));
}
}