dawdler-server-plug-rabbitmq
模块介绍
实现dawdler-server端注入RabbitProvider与RabbitListener注解的功能.
1. pom中引入依赖
<groupId>club.dawdler</groupId>
<artifactId>dawdler-server-plug-rabbitmq</artifactId>
2. 使用方式
发送端者: 通过@RabbitInjector注解标识全局变量为RabbitProvider类型的变量即可.
消费者: 通过@RabbitListener标识消费者方法,方法参数为Message 类型.
public class UserServiceImpl implements UserService {
@RabbitInjector("myRabbitmq")//myRabbitmq为配置文件的名称,不包含后缀properties
RabbitProvider rabbitProvider;
public void pushMssage(String message) {
rabbitProvider.publish("", "queueName", null, message.getBytes());//使用rabbitProvider对象
return null;
}
@RabbitListener(fileName = "myRabbitmq",queueName = "test") //监听test队列
public void consumer(Message message) {
System.out.println(new String(message.getBody()));
}
}