package examples;
import io.vertx.ext.consul.*;
public class Events {
public void sendWithName(ConsulClient consulClient) {
consulClient.fireEvent("eventName", res -> {
if (res.succeeded()) {
System.out.println("Event sent");
System.out.println("id: " + res.result().getId());
} else {
res.cause().printStackTrace();
}
});
}
public void sendWithOptions(ConsulClient consulClient) {
EventOptions opts = new EventOptions()
.setTag("tag")
.setPayload("message");
consulClient.fireEventWithOptions("eventName", opts, res -> {
if (res.succeeded()) {
System.out.println("Event sent");
System.out.println("id: " + res.result().getId());
} else {
res.cause().printStackTrace();
}
});
}
public void list(ConsulClient consulClient) {
consulClient.listEvents(res -> {
if (res.succeeded()) {
System.out.println("Consul index: " + res.result().getIndex());
for(Event event: res.result().getList()) {
System.out.println("Event id: " + event.getId());
System.out.println("Event name: " + event.getName());
System.out.println("Event payload: " + event.getPayload());
}
} else {
res.cause().printStackTrace();
}
});
}
public void listWithOptions(ConsulClient consulClient, long lastIndex) {
EventListOptions opts = new EventListOptions()
.setName("eventName")
.setBlockingOptions(new BlockingQueryOptions().setIndex(lastIndex));
consulClient.listEventsWithOptions(opts, res -> {
if (res.succeeded()) {
System.out.println("Consul index: " + res.result().getIndex());
for(Event event: res.result().getList()) {
System.out.println("Event id: " + event.getId());
}
} else {
res.cause().printStackTrace();
}
});
}
}