Skip to content

Commit

Permalink
Add example for publisher confirms.
Browse files Browse the repository at this point in the history
  • Loading branch information
aangelidis committed Mar 14, 2017
1 parent 010e5ac commit e2e9490
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/examples/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ public void basicPublish(RabbitMQClient client) {
});
}

public void basicPublishWithConfirm(RabbitMQClient client) {
JsonObject message = new JsonObject().put("body", "Hello RabbitMQ, from Vert.x !");

// Put the channel in confirm mode. This can be done once at init.
client.confirmSelect(confirmResult -> {
if(confirmResult.succeeded()) {
client.basicPublish("", "my.queue", message, pubResult -> {
if (pubResult.succeeded()) {
// Check the message got confirmed by the broker.
client.waitForConfirms(waitResult -> {
if(waitResult.succeeded())
System.out.println("Message published !");
else
waitResult.cause().printStackTrace();
});
} else {
pubResult.cause().printStackTrace();
}
});
} else {
confirmResult.cause().printStackTrace();
}
});

}


public void basicConsume(Vertx vertx, RabbitMQClient client) {
// Create the event bus handler which messages will be sent to
vertx.eventBus().consumer("my.address", msg -> {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/vertx/rabbitmq/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
* {@link examples.Examples#basicPublish}
* ----
*
* === Publish with confirm
*
* Publish a message to a queue and confirm the broker acknowledged it.
*
* [source,$lang]
* ----
* {@link examples.Examples#basicPublishWithConfirm}
* ----
*
* === Consume
*
* Consume messages from a queue
Expand Down

0 comments on commit e2e9490

Please sign in to comment.