use of org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties 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);
}
use of org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties in project hono by eclipse.
the class KafkaApplicationClientImplTest method setUp.
/**
* Sets up fixture.
*
* @param vertx The vert.x instance to use.
*/
@BeforeEach
void setUp(final Vertx vertx) {
final MockProducer<String, Buffer> mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final CachingKafkaProducerFactory<String, Buffer> producerFactory = CachingKafkaProducerFactory.testFactory(vertx, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
tenantId = UUID.randomUUID().toString();
mockConsumer = new KafkaMockConsumer(OffsetResetStrategy.EARLIEST);
final CommonKafkaClientConfigProperties commonConfig = new CommonKafkaClientConfigProperties();
commonConfig.setCommonClientConfig(Map.of(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "kafka"));
final MessagingKafkaConsumerConfigProperties consumerConfig = new MessagingKafkaConsumerConfigProperties();
consumerConfig.setCommonClientConfig(commonConfig);
consumerConfig.setConsumerConfig(Map.of("client.id", "application-test-consumer"));
final MessagingKafkaProducerConfigProperties producerConfig = new MessagingKafkaProducerConfigProperties();
producerConfig.setCommonClientConfig(commonConfig);
producerConfig.setProducerConfig(Map.of("client.id", "application-test-sender"));
client = new KafkaApplicationClientImpl(vertx, consumerConfig, producerFactory, producerConfig);
client.setKafkaConsumerFactory(() -> mockConsumer);
}
use of org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties in project hono by eclipse.
the class KafkaBasedCommandConsumerFactoryImplIT method getKafkaBasedCommandConsumerFactory.
private KafkaBasedCommandConsumerFactoryImpl getKafkaBasedCommandConsumerFactory(final Supplier<Future<Void>> targetAdapterInstanceGetterCompletionFutureSupplier, final String tenantToHandleCommandsFor) {
final KafkaProducerFactory<String, Buffer> producerFactory = CachingKafkaProducerFactory.sharedFactory(vertx);
final TenantClient tenantClient = getTenantClient();
final CommandTargetMapper commandTargetMapper = new CommandTargetMapper() {
@Override
public Future<JsonObject> getTargetGatewayAndAdapterInstance(final String tenantId, final String deviceId, final SpanContext context) {
final JsonObject jsonObject = new JsonObject();
jsonObject.put(DeviceConnectionConstants.FIELD_ADAPTER_INSTANCE_ID, adapterInstanceId);
jsonObject.put(DeviceConnectionConstants.FIELD_PAYLOAD_DEVICE_ID, deviceId);
if (!tenantId.equals(tenantToHandleCommandsFor)) {
return Future.failedFuture("ignoring command for other tenant " + tenantId);
}
if (targetAdapterInstanceGetterCompletionFutureSupplier == null) {
return Future.succeededFuture(jsonObject);
}
return targetAdapterInstanceGetterCompletionFutureSupplier.get().map(jsonObject);
}
};
final Span span = TracingMockSupport.mockSpan();
final Tracer tracer = TracingMockSupport.mockTracer(span);
final MessagingKafkaConsumerConfigProperties kafkaConsumerConfig = new MessagingKafkaConsumerConfigProperties();
kafkaConsumerConfig.setConsumerConfig(Map.of(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS));
final CommandRouterMetrics metrics = mock(CommandRouterMetrics.class);
when(metrics.startTimer()).thenReturn(Timer.start());
final var kafkaBasedCommandConsumerFactoryImpl = new KafkaBasedCommandConsumerFactoryImpl(vertx, tenantClient, commandTargetMapper, producerFactory, IntegrationTestSupport.getKafkaProducerConfig(), IntegrationTestSupport.getKafkaProducerConfig(), kafkaConsumerConfig, metrics, NoopKafkaClientMetricsSupport.INSTANCE, tracer, null);
kafkaBasedCommandConsumerFactoryImpl.setGroupId(commandRouterGroupId);
componentsToStopAfterTest.add(kafkaBasedCommandConsumerFactoryImpl);
return kafkaBasedCommandConsumerFactoryImpl;
}
use of org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties in project hono by eclipse.
the class KafkaBasedCommandSenderTest method setUp.
/**
* Sets up fixture.
*
* @param vertx The vert.x instance to use.
*/
@BeforeEach
void setUp(final Vertx vertx) {
this.vertx = vertx;
consumerConfig = new MessagingKafkaConsumerConfigProperties();
mockConsumer = new KafkaMockConsumer(OffsetResetStrategy.LATEST);
producerConfig = new MessagingKafkaProducerConfigProperties();
producerConfig.setProducerConfig(Map.of("client.id", "application-test-sender"));
span = TracingMockSupport.mockSpan();
tracer = TracingMockSupport.mockTracer(span);
mockProducer = KafkaClientUnitTestHelper.newMockProducer(true);
final var producerFactory = CachingKafkaProducerFactory.testFactory(vertx, (n, c) -> KafkaClientUnitTestHelper.newKafkaProducer(mockProducer));
commandSender = new KafkaBasedCommandSender(vertx, consumerConfig, producerFactory, producerConfig, tracer);
tenantId = UUID.randomUUID().toString();
deviceId = UUID.randomUUID().toString();
}
use of org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties in project hono by eclipse.
the class IntegrationTestSupport method getKafkaConsumerConfig.
/**
* Creates properties for connecting a consumer to Kafka.
*
* @return The properties.
*/
public static MessagingKafkaConsumerConfigProperties getKafkaConsumerConfig() {
LOGGER.info("Configured to connect to Kafka on {}", IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS);
final MessagingKafkaConsumerConfigProperties consumerConfig = new MessagingKafkaConsumerConfigProperties();
consumerConfig.setConsumerConfig(Map.of(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS, ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest", ConsumerConfig.GROUP_ID_CONFIG, "its-" + UUID.randomUUID()));
return consumerConfig;
}
Aggregations