use of org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender in project hono by eclipse.
the class KafkaBasedEventSenderIT method initProducer.
/**
* Creates the event sender.
*/
@BeforeEach
void initProducer() {
producerFactory = CachingKafkaProducerFactory.nonSharedFactory(vertx);
KafkaBasedEventSender = new KafkaBasedEventSender(vertx, producerFactory, IntegrationTestSupport.getKafkaProducerConfig(), false, NoopTracerFactory.create());
}
use of org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender in project hono by eclipse.
the class ApplicationConfig method eventSenderProvider.
/**
* Creates a client for publishing events via the configured messaging systems.
*
* @return The client.
*/
@Bean
@Scope("prototype")
public MessagingClientProvider<EventSender> eventSenderProvider() {
final MessagingClientProvider<EventSender> result = new MessagingClientProvider<>();
if (downstreamSenderConfig().isHostConfigured()) {
result.setClient(new ProtonBasedDownstreamSender(HonoConnection.newConnection(vertx(), downstreamSenderConfig(), tracer()), SendMessageSampler.Factory.noop(), true, true));
}
if (kafkaEventConfig().isConfigured()) {
final KafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.sharedFactory(vertx());
result.setClient(new KafkaBasedEventSender(vertx(), factory, kafkaEventConfig(), true, tracer()));
}
healthCheckServer().registerHealthCheckResources(ServiceClientAdapter.forClient(result));
return result;
}
use of org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender in project hono by eclipse.
the class AmqpServerFactory method eventSenderProvider.
/**
* Creates a client for publishing events via the configured messaging systems.
*
* @return The client.
*/
private MessagingClientProvider<EventSender> eventSenderProvider() {
final MessagingClientProvider<EventSender> result = new MessagingClientProvider<>();
if (downstreamSenderConfig.isHostConfigured()) {
result.setClient(new ProtonBasedDownstreamSender(HonoConnection.newConnection(vertx, downstreamSenderConfig, tracer), SendMessageSampler.Factory.noop(), true, true));
}
if (eventKafkaProducerConfig.isConfigured()) {
final KafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.sharedFactory(vertx);
result.setClient(new KafkaBasedEventSender(vertx, factory, eventKafkaProducerConfig, true, tracer));
}
healthCheckServer.registerHealthCheckResources(ServiceClientAdapter.forClient(result));
return result;
}
use of org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender in project hono by eclipse.
the class AbstractProtocolAdapterApplication method setCollaborators.
/**
* Sets collaborators required by all protocol adapters.
*
* @param adapter The adapter to set the collaborators on.
* @throws NullPointerException if adapter is {@code null}
* @throws IllegalStateException if no connection to the Command Router service has been configured.
*/
protected void setCollaborators(final AbstractProtocolAdapterBase<?> adapter) {
Objects.requireNonNull(adapter);
final DeviceRegistrationClient registrationClient = registrationClient();
final MessagingClientProvider<TelemetrySender> telemetrySenderProvider = new MessagingClientProvider<>();
final MessagingClientProvider<EventSender> eventSenderProvider = new MessagingClientProvider<>();
final MessagingClientProvider<CommandResponseSender> commandResponseSenderProvider = new MessagingClientProvider<>();
final KafkaClientMetricsSupport kafkaClientMetricsSupport = kafkaClientMetricsSupport(kafkaMetricsOptions);
final var tenantClient = tenantClient();
if (kafkaEventConfig.isConfigured()) {
LOG.info("Kafka client configuration present, adding Kafka messaging clients");
final KafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.sharedFactory(vertx);
factory.setMetricsSupport(kafkaClientMetricsSupport);
telemetrySenderProvider.setClient(new KafkaBasedTelemetrySender(vertx, factory, kafkaTelemetryConfig, protocolAdapterProperties.isDefaultsEnabled(), tracer));
eventSenderProvider.setClient(new KafkaBasedEventSender(vertx, factory, kafkaEventConfig, protocolAdapterProperties.isDefaultsEnabled(), tracer));
commandResponseSenderProvider.setClient(new KafkaBasedCommandResponseSender(vertx, factory, kafkaCommandResponseConfig, tracer));
}
if (downstreamSenderConfig.isHostConfigured()) {
telemetrySenderProvider.setClient(downstreamSender());
eventSenderProvider.setClient(downstreamSender());
commandResponseSenderProvider.setClient(new ProtonBasedCommandResponseSender(HonoConnection.newConnection(vertx, commandResponseSenderConfig(), tracer), messageSamplerFactory, protocolAdapterProperties.isJmsVendorPropsEnabled()));
}
final MessagingClientProviders messagingClientProviders = new MessagingClientProviders(telemetrySenderProvider, eventSenderProvider, commandResponseSenderProvider);
if (commandRouterConfig.isHostConfigured()) {
final CommandRouterClient commandRouterClient = commandRouterClient();
adapter.setCommandRouterClient(commandRouterClient);
final CommandRouterCommandConsumerFactory commandConsumerFactory = commandConsumerFactory(commandRouterClient);
if (commandConsumerConfig.isHostConfigured()) {
commandConsumerFactory.registerInternalCommandConsumer((id, handlers) -> new ProtonBasedInternalCommandConsumer(commandConsumerConnection(), id, handlers));
}
final CommandResponseSender kafkaCommandResponseSender = messagingClientProviders.getCommandResponseSenderProvider().getClient(MessagingType.kafka);
if (kafkaCommandInternalConfig.isConfigured() && kafkaCommandConfig.isConfigured() && kafkaCommandResponseSender != null) {
commandConsumerFactory.registerInternalCommandConsumer((id, handlers) -> new KafkaBasedInternalCommandConsumer(vertx, kafkaCommandInternalConfig, kafkaCommandConfig, tenantClient, kafkaCommandResponseSender, id, handlers, tracer).setMetricsSupport(kafkaClientMetricsSupport));
}
adapter.setCommandConsumerFactory(commandConsumerFactory);
} else {
throw new IllegalStateException("No Command Router connection configured");
}
adapter.setMessagingClientProviders(messagingClientProviders);
Optional.ofNullable(connectionEventProducer()).ifPresent(adapter::setConnectionEventProducer);
adapter.setCredentialsClient(credentialsClient());
adapter.setHealthCheckServer(healthCheckServer);
adapter.setRegistrationClient(registrationClient);
adapter.setResourceLimitChecks(prometheusResourceLimitChecks(resourceLimitChecksConfig, tenantClient));
adapter.setTenantClient(tenantClient);
adapter.setTracer(tracer);
}
use of org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender in project hono by eclipse.
the class AmqpServerFactory method eventSenderProvider.
/**
* Creates a client for publishing events via the configured messaging systems.
*
* @return The client.
*/
private MessagingClientProvider<EventSender> eventSenderProvider() {
final MessagingClientProvider<EventSender> result = new MessagingClientProvider<>();
if (downstreamSenderConfig.isHostConfigured()) {
result.setClient(new ProtonBasedDownstreamSender(HonoConnection.newConnection(vertx, downstreamSenderConfig, tracer), SendMessageSampler.Factory.noop(), true, true));
}
if (eventKafkaProducerConfig.isConfigured()) {
final KafkaProducerFactory<String, Buffer> factory = CachingKafkaProducerFactory.sharedFactory(vertx);
result.setClient(new KafkaBasedEventSender(vertx, factory, eventKafkaProducerConfig, true, tracer));
}
healthCheckServer.registerHealthCheckResources(ServiceClientAdapter.forClient(result));
return result;
}
Aggregations