use of org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties 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.CommonKafkaClientConfigProperties 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.CommonKafkaClientConfigProperties in project hono by eclipse.
the class NotificationKafkaConsumerConfigPropertiesTest method testThatGetConsumerConfigReturnsGivenPropertiesWithCommonProperties.
/**
* Verifies that properties provided with {@link NotificationKafkaConsumerConfigProperties#setConsumerConfig(Map)}
* and {@link AbstractKafkaConfigProperties#setCommonClientConfig(CommonKafkaClientConfigProperties)} are returned
* in {@link NotificationKafkaConsumerConfigProperties#getConsumerConfig(String)}, with the consumer config
* properties having precedence.
*/
@Test
public void testThatGetConsumerConfigReturnsGivenPropertiesWithCommonProperties() {
final CommonKafkaClientConfigProperties commonConfig = new CommonKafkaClientConfigProperties();
commonConfig.setCommonClientConfig(Map.of("foo", "toBeOverridden", "common", "commonValue"));
final NotificationKafkaConsumerConfigProperties config = new NotificationKafkaConsumerConfigProperties();
config.setCommonClientConfig(commonConfig);
config.setConsumerConfig(Map.of("foo", "bar"));
final Map<String, String> consumerConfig = config.getConsumerConfig("consumerName");
assertThat(consumerConfig.get("foo")).isEqualTo("bar");
assertThat(consumerConfig.get("common")).isEqualTo("commonValue");
}
use of org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties in project hono by eclipse.
the class NotificationKafkaProducerConfigPropertiesTest method testThatGetProducerConfigReturnsGivenPropertiesWithCommonProperties.
/**
* Verifies that properties provided with {@link NotificationKafkaProducerConfigProperties#setProducerConfig(Map)}
* and {@link AbstractKafkaConfigProperties#setCommonClientConfig(CommonKafkaClientConfigProperties)} are returned
* in {@link NotificationKafkaProducerConfigProperties#getProducerConfig(String)}, with the producer config
* properties having precedence.
*/
@Test
public void testThatGetProducerConfigReturnsGivenPropertiesWithCommonProperties() {
final CommonKafkaClientConfigProperties commonConfig = new CommonKafkaClientConfigProperties();
commonConfig.setCommonClientConfig(Map.of("foo", "toBeOverridden", "common", "commonValue"));
final NotificationKafkaProducerConfigProperties config = new NotificationKafkaProducerConfigProperties();
config.setCommonClientConfig(commonConfig);
config.setProducerConfig(Map.of("foo", "bar"));
final Map<String, String> producerConfig = config.getProducerConfig("producerName");
assertThat(producerConfig.get("foo")).isEqualTo("bar");
assertThat(producerConfig.get("common")).isEqualTo("commonValue");
}
use of org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties in project hono by eclipse.
the class KafkaProducerConfigPropertiesTest method testThatGetProducerConfigReturnsGivenPropertiesWithCommonProperties.
/**
* Verifies that properties provided with {@link KafkaProducerConfigProperties#setProducerConfig(Map)} and
* {@link AbstractKafkaConfigProperties#setCommonClientConfig(CommonKafkaClientConfigProperties)} are returned in
* {@link KafkaProducerConfigProperties#getProducerConfig(String)}, with the producer config properties having
* precedence.
*/
@Test
public void testThatGetProducerConfigReturnsGivenPropertiesWithCommonProperties() {
final CommonKafkaClientConfigProperties commonConfig = new CommonKafkaClientConfigProperties();
commonConfig.setCommonClientConfig(Map.of("foo", "toBeOverridden", "common", "commonValue"));
config.setCommonClientConfig(commonConfig);
config.setProducerConfig(Map.of("foo", "bar"));
final Map<String, String> producerConfig = config.getProducerConfig("producerName");
assertThat(producerConfig.get("foo")).isEqualTo("bar");
assertThat(producerConfig.get("common")).isEqualTo("commonValue");
}
Aggregations