Vert.x Spring Boot AMQP starter adapts Vert.x AMQP client to be used with Reactor API.
Add the starter dependency to your pom.xml
.
<dependency>
<groupId>dev.snowdrop</groupId>
<artifactId>vertx-spring-boot-starter-amqp</artifactId>
</dependency>
Inject AmqpClient wherever you need to send or receive an AMQP message.
@Component
public class MyComponent {
private final AmqpClient amqpClient;
public MyComponent(AmqpClient amqpClient) {
this.amqpClient = amqpClient;
}
// ...
}
Create messages using message builder.
@Component
public class MyComponent {
// ...
public AmqpMessage createMessage(String id, String body) {
return AmqpMessage.create()
.id(id)
.withBody(body)
.build();
}
}
Send messages with a sender.
@Component
public class MyComponent {
private final AmqpClient amqpClient;
// ...
public Mono<Void> send(String address, AmqpMessage message) {
return amqpClient.createSender(address)
.map(sender -> sender.send(message))
.flatMap(AmqpSender::close);
}
}
Receive messages with a receiver.
@Component
public class MyComponent {
private final AmqpClient amqpClient;
// ...
public Flux<AmqpMessage> receive(String address) {
return client.createReceiver(address)
.flatMapMany(receiver -> receiver.flux()
.doOnCancel(() -> receiver.close().block()));
}
}
All options from io.vertx.amqp.AmqpClientOptions
are mapped to Spring properties under vertx.amqp
prefix.
For example, to set an AMQP broker's host add the following property to your application.properties
file.
vertx.amqp.host=localhost
For the full list of available properties see AmqpProperties.java.
In addition, sender and receiver specific properties can be used when creating such objects. For the full set of options see AmqpSenderOptions.java and AmqpReceiverOptions.java respectively.