Skip to main content

dawdler-server-plug-rabbitmq

Module introduction​

Implements injection of the RabbitProvider and RabbitListener annotations on the dawdler-server side.

1. Add the dependency to the pom​

<groupId>club.dawdler</groupId>
<artifactId>dawdler-server-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.


public class UserServiceImpl implements UserService {

@RabbitInjector("myRabbitmq")//myRabbitmq is the name of the configuration file, without the properties suffix
RabbitProvider rabbitProvider;

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()));
}

}

2.1 The three components that support injection on the dawdler server side​

  1. DawdlerFilter service filter

  2. DawdlerServiceListener listener

  3. Interface implementation classes annotated with @Service