Search in sources :

Example 1 with KafkaApplicationClientImpl

use of org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl in project hono by eclipse.

the class HonoExampleApplicationBase method createKafkaApplicationClient.

/**
 * Creates an application client for Kafka based messaging. Unlike with AMQP, the Kafka clients manage their
 * connections to the cluster internally.
 * <p>
 * NB: if you want to integrate this code with your own software, it might be necessary to copy the trust store to
 * your project as well and adopt the file path.
 */
private ApplicationClient<? extends MessageContext> createKafkaApplicationClient() {
    final Map<String, String> properties = new HashMap<>();
    properties.put("bootstrap.servers", HonoExampleConstants.HONO_MESSAGING_HOST + ":" + port);
    // add the following lines with appropriate values to enable TLS
    // properties.put("ssl.truststore.location", "/path/to/file");
    // properties.put("ssl.truststore.password", "secret");
    final CommonKafkaClientConfigProperties commonClientConfig = new CommonKafkaClientConfigProperties();
    commonClientConfig.setCommonClientConfig(properties);
    final MessagingKafkaConsumerConfigProperties consumerConfig = new MessagingKafkaConsumerConfigProperties();
    consumerConfig.setCommonClientConfig(commonClientConfig);
    consumerConfig.setConsumerConfig(Map.of("group.id", KAFKA_CONSUMER_GROUP_ID));
    final MessagingKafkaProducerConfigProperties producerConfig = new MessagingKafkaProducerConfigProperties();
    producerConfig.setCommonClientConfig(commonClientConfig);
    final KafkaProducerFactory<String, Buffer> producerFactory = CachingKafkaProducerFactory.sharedFactory(vertx);
    return new KafkaApplicationClientImpl(vertx, consumerConfig, producerFactory, producerConfig);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MessagingKafkaConsumerConfigProperties(org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties) HashMap(java.util.HashMap) MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties) CommonKafkaClientConfigProperties(org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties) KafkaApplicationClientImpl(org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl)

Example 2 with KafkaApplicationClientImpl

use of org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl in project hono by eclipse.

the class IntegrationTestSupport method init.

/**
 * Connects to Kafka.
 * <p>
 * Also creates an HTTP client for accessing the Device Registry.
 *
 * @param kafkaDownstreamProps The properties for connecting to Kafka.
 *
 * @return A future indicating the outcome of the operation.
 */
public Future<Void> init(final MessagingKafkaConsumerConfigProperties kafkaDownstreamProps) {
    initRegistryClient();
    kafkaProducerFactory = CachingKafkaProducerFactory.sharedFactory(vertx);
    applicationClient = new KafkaApplicationClientImpl(vertx, kafkaDownstreamProps, kafkaProducerFactory, getKafkaProducerConfig());
    return Future.succeededFuture();
}
Also used : KafkaApplicationClientImpl(org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl)

Aggregations

KafkaApplicationClientImpl (org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl)2 Buffer (io.vertx.core.buffer.Buffer)1 HashMap (java.util.HashMap)1 CommonKafkaClientConfigProperties (org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties)1 MessagingKafkaConsumerConfigProperties (org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties)1 MessagingKafkaProducerConfigProperties (org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties)1