Search in sources :

Example 1 with MessagingKafkaProducerConfigProperties

use of org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties in project hono by eclipse.

the class AppConfiguration method messagingKafkaProducerConfig.

/**
 * Exposes Kafka producer configuration properties as a Spring bean.
 *
 * @param commonKafkaClientConfig The common Kafka client configuration.
 * @return The properties.
 */
@ConfigurationProperties(prefix = "hono.kafka.producer")
@Profile("kafka")
@Bean
public MessagingKafkaProducerConfigProperties messagingKafkaProducerConfig(final CommonKafkaClientConfigProperties commonKafkaClientConfig) {
    final MessagingKafkaProducerConfigProperties configProperties = new MessagingKafkaProducerConfigProperties();
    configProperties.setCommonClientConfig(commonKafkaClientConfig);
    return configProperties;
}
Also used : MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) Profile(org.springframework.context.annotation.Profile) Bean(org.springframework.context.annotation.Bean)

Example 2 with MessagingKafkaProducerConfigProperties

use of org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties 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 3 with MessagingKafkaProducerConfigProperties

use of org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties in project hono by eclipse.

the class IntegrationTestSupport method getKafkaProducerConfig.

/**
 * Creates properties for connecting a producer to Kafka.
 *
 * @return The properties.
 */
public static MessagingKafkaProducerConfigProperties getKafkaProducerConfig() {
    LOGGER.info("Configured to connect to Kafka on {}", IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS);
    final MessagingKafkaProducerConfigProperties consumerConfig = new MessagingKafkaProducerConfigProperties();
    consumerConfig.setProducerConfig(Map.of(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, IntegrationTestSupport.DOWNSTREAM_BOOTSTRAP_SERVERS));
    return consumerConfig;
}
Also used : MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties)

Example 4 with MessagingKafkaProducerConfigProperties

use of org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties 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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MessagingKafkaConsumerConfigProperties(org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties) MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties) CommonKafkaClientConfigProperties(org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties) KafkaMockConsumer(org.eclipse.hono.kafka.test.KafkaMockConsumer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with MessagingKafkaProducerConfigProperties

use of org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties in project hono by eclipse.

the class ApplicationConfig method kafkaEventConfig.

/**
 * Exposes configuration properties for the Kafka producer that publishes events as a Spring bean.
 *
 * @return The properties.
 */
@ConfigurationProperties(prefix = "hono.kafka.event")
@Bean
public MessagingKafkaProducerConfigProperties kafkaEventConfig() {
    final MessagingKafkaProducerConfigProperties configProperties = new MessagingKafkaProducerConfigProperties();
    configProperties.setCommonClientConfig(commonKafkaClientConfig());
    return configProperties;
}
Also used : MessagingKafkaProducerConfigProperties(org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) ObjectFactoryCreatingFactoryBean(org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MessagingKafkaProducerConfigProperties (org.eclipse.hono.client.kafka.producer.MessagingKafkaProducerConfigProperties)10 BeforeEach (org.junit.jupiter.api.BeforeEach)6 Vertx (io.vertx.core.Vertx)3 EventBus (io.vertx.core.eventbus.EventBus)3 MessagingKafkaConsumerConfigProperties (org.eclipse.hono.client.kafka.consumer.MessagingKafkaConsumerConfigProperties)3 Buffer (io.vertx.core.buffer.Buffer)2 CommonKafkaClientConfigProperties (org.eclipse.hono.client.kafka.CommonKafkaClientConfigProperties)2 KafkaMockConsumer (org.eclipse.hono.kafka.test.KafkaMockConsumer)2 TenantObject (org.eclipse.hono.util.TenantObject)2 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)2 Bean (org.springframework.context.annotation.Bean)2 HashMap (java.util.HashMap)1 KafkaApplicationClientImpl (org.eclipse.hono.application.client.kafka.impl.KafkaApplicationClientImpl)1 ObjectFactoryCreatingFactoryBean (org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean)1 Profile (org.springframework.context.annotation.Profile)1