use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class HonoConsumerBase method consumeData.
/**
* Initiate the connection and set the message handling method to treat data that is received.
*
* @throws Exception Thrown if the latch is interrupted during waiting or if the read from System.in throws an IOException.
*/
protected void consumeData() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final Future<MessageConsumer> consumerFuture = Future.future();
consumerFuture.setHandler(result -> {
if (!result.succeeded()) {
System.err.println("honoClient could not create telemetry consumer for " + HonoExampleConstants.HONO_AMQP_CONSUMER_HOST + ":" + HonoExampleConstants.HONO_AMQP_CONSUMER_PORT + " : " + result.cause());
}
latch.countDown();
});
honoClient.connect(new ProtonClientOptions()).compose(connectedClient -> {
if (eventMode) {
return connectedClient.createEventConsumer(HonoExampleConstants.TENANT_ID, this::handleMessage, closeHook -> System.err.println("remotely detached consumer link"));
} else {
return connectedClient.createTelemetryConsumer(HonoExampleConstants.TENANT_ID, this::handleMessage, closeHook -> System.err.println("remotely detached consumer link"));
}
}).setHandler(consumerFuture.completer());
latch.await();
if (consumerFuture.succeeded()) {
System.in.read();
}
vertx.close();
}
use of io.vertx.proton.ProtonClientOptions in project hono by eclipse.
the class AuthenticationServerClient method verifyPlain.
/**
* Verifies username/password credentials with a remote authentication server using SASL PLAIN.
*
* @param authzid The identity to act as.
* @param authcid The username.
* @param password The password.
* @param authenticationResultHandler The handler to invoke with the authentication result. On successful authentication,
* the result contains a JWT with the authenticated user's claims.
*/
public void verifyPlain(final String authzid, final String authcid, final String password, final Handler<AsyncResult<HonoUser>> authenticationResultHandler) {
ProtonClientOptions options = new ProtonClientOptions();
options.setReconnectAttempts(3).setReconnectInterval(50);
options.addEnabledSaslMechanism(AuthenticationConstants.MECHANISM_PLAIN);
factory.connect(options, authcid, password, null, null, conAttempt -> {
if (conAttempt.failed()) {
authenticationResultHandler.handle(Future.failedFuture("cannot connect to Authentication service"));
} else {
final ProtonConnection openCon = conAttempt.result();
final Future<HonoUser> userTracker = Future.future();
userTracker.setHandler(s -> {
if (s.succeeded()) {
authenticationResultHandler.handle(Future.succeededFuture(s.result()));
} else {
authenticationResultHandler.handle(Future.failedFuture(s.cause()));
}
ProtonConnection con = conAttempt.result();
if (con != null) {
LOG.debug("closing connection to Authentication service");
con.close();
}
});
vertx.setTimer(5000, tid -> {
if (!userTracker.isComplete()) {
userTracker.fail("time out reached while waiting for token from Authentication service");
}
});
getToken(openCon, userTracker);
}
});
}
Aggregations