use of org.eclipse.hono.client.MessageConsumer 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();
}
Aggregations