package examples;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.core.json.JsonObject;
import io.vertx.serviceproxy.ServiceBinder;
import io.vertx.serviceproxy.ServiceProxyBuilder;
public class Examples {
public void example1(Vertx vertx) {
JsonObject message = new JsonObject();
message.put("collection", "mycollection")
.put("document", new JsonObject().put("name", "tim"));
DeliveryOptions options = new DeliveryOptions().addHeader("action", "save");
vertx.eventBus().send("database-service-address", message, options, res2 -> {
if (res2.succeeded()) {
} else {
}
});
}
public void example2(Vertx vertx) {
SomeDatabaseService service = SomeDatabaseService.createProxy(vertx,
"database-service-address");
service.save("mycollection", new JsonObject().put("name", "tim"), res2 -> {
if (res2.succeeded()) {
}
});
}
public void register(Vertx vertx) {
SomeDatabaseService service = new SomeDatabaseServiceImpl();
new ServiceBinder(vertx)
.setAddress("database-service-address")
.register(SomeDatabaseService.class, service);
}
public void unregister(Vertx vertx) {
ServiceBinder binder = new ServiceBinder(vertx);
SomeDatabaseService service = new SomeDatabaseServiceImpl();
MessageConsumer<JsonObject> consumer = binder
.setAddress("database-service-address")
.register(SomeDatabaseService.class, service);
binder.unregister(consumer);
}
public void proxyCreation(Vertx vertx, DeliveryOptions options) {
ServiceProxyBuilder builder = new ServiceProxyBuilder(vertx).setAddress("database-service-address");
SomeDatabaseService service = builder.build(SomeDatabaseService.class);
SomeDatabaseService service2 = builder.setOptions(options).build(SomeDatabaseService.class);
}
}