package examples;
import io.vertx.core.json.JsonObject;
import io.vertx.servicediscovery.ServiceDiscovery;
import io.vertx.servicediscovery.Record;
import io.vertx.servicediscovery.ServiceReference;
import io.vertx.servicediscovery.types.JDBCDataSource;
import io.vertx.ext.jdbc.JDBCClient;
public class JDBCDataSourceExamples {
public void example1(ServiceDiscovery discovery) {
Record record = JDBCDataSource.createRecord(
"some-data-source-service",
new JsonObject().put("url", "some jdbc url"),
new JsonObject().put("some-metadata", "some-value")
);
discovery.publish(record, ar -> {
});
}
public void example2(ServiceDiscovery discovery) {
discovery.getRecord(
new JsonObject().put("name", "some-data-source-service"),
ar -> {
if (ar.succeeded() && ar.result() != null) {
ServiceReference reference = discovery.getReferenceWithConfiguration(
ar.result(),
new JsonObject().put("username", "clement").put("password", "*****"));
JDBCClient client = reference.getAs(JDBCClient.class);
reference.release();
}
});
}
public void example3(ServiceDiscovery discovery) {
JDBCDataSource.<JsonObject>getJDBCClient(discovery,
new JsonObject().put("name", "some-data-source-service"),
new JsonObject().put("username", "clement").put("password", "*****"),
ar -> {
if (ar.succeeded()) {
JDBCClient client = ar.result();
ServiceDiscovery.releaseServiceObject(discovery, client);
}
});
}
}