Search in sources :

Example 1 with EventSender

use of org.eclipse.hono.client.telemetry.EventSender in project hono by eclipse.

the class AbstractProtocolAdapterBaseTest method testGetCommandResponseSenderConfiguredOnTenant.

/**
 * Verifies that when the messaging system to be used, as configured for the command response, is not available,
 * then the messaging system type configuration from the tenant is used.
 */
@Test
public void testGetCommandResponseSenderConfiguredOnTenant() {
    final var commandResponseSenderProvider = new MessagingClientProvider<CommandResponseSender>().setClient(amqpCommandResponseSender);
    messagingClientProviders = new MessagingClientProviders(new MessagingClientProvider<TelemetrySender>().setClient(amqpTelemetrySender), new MessagingClientProvider<EventSender>().setClient(amqpEventSender), commandResponseSenderProvider);
    properties = new ProtocolAdapterProperties();
    adapter = newProtocolAdapter(properties, ADAPTER_NAME);
    setCollaborators(adapter);
    final CommandResponse response = CommandResponse.fromRequestId(Commands.encodeRequestIdParameters("", "replyTo", "4711", MessagingType.kafka), Constants.DEFAULT_TENANT, "4711", null, null, HttpURLConnection.HTTP_OK);
    final TenantObject tenant = new TenantObject("tenant", true);
    final var device = new RegistrationAssertion("4711");
    tenant.setProperty(TenantConstants.FIELD_EXT, Map.of(TenantConstants.FIELD_EXT_MESSAGING_TYPE, MessagingType.amqp.name()));
    adapter.sendCommandResponse(tenant, device, response, null);
    verify(amqpCommandResponseSender).sendCommandResponse(eq(tenant), eq(device), eq(response), any());
}
Also used : ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) EventSender(org.eclipse.hono.client.telemetry.EventSender) TelemetrySender(org.eclipse.hono.client.telemetry.TelemetrySender) CommandResponse(org.eclipse.hono.client.command.CommandResponse) Test(org.junit.jupiter.api.Test)

Example 2 with EventSender

use of org.eclipse.hono.client.telemetry.EventSender 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;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) ProtonBasedDownstreamSender(org.eclipse.hono.client.telemetry.amqp.ProtonBasedDownstreamSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) EventSender(org.eclipse.hono.client.telemetry.EventSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) Scope(org.springframework.context.annotation.Scope) ObjectFactoryCreatingFactoryBean(org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with EventSender

use of org.eclipse.hono.client.telemetry.EventSender 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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) KafkaBasedTelemetrySender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedTelemetrySender) CommandRouterClient(org.eclipse.hono.client.command.CommandRouterClient) ProtonBasedCommandRouterClient(org.eclipse.hono.client.command.amqp.ProtonBasedCommandRouterClient) KafkaBasedCommandResponseSender(org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender) ProtonBasedDeviceRegistrationClient(org.eclipse.hono.client.registry.amqp.ProtonBasedDeviceRegistrationClient) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) ProtonBasedCommandResponseSender(org.eclipse.hono.client.command.amqp.ProtonBasedCommandResponseSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) MicrometerKafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.MicrometerKafkaClientMetricsSupport) KafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.KafkaClientMetricsSupport) NoopKafkaClientMetricsSupport(org.eclipse.hono.client.kafka.metrics.NoopKafkaClientMetricsSupport) CommandRouterCommandConsumerFactory(org.eclipse.hono.client.command.CommandRouterCommandConsumerFactory) MessagingClientProviders(org.eclipse.hono.adapter.MessagingClientProviders) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) KafkaBasedInternalCommandConsumer(org.eclipse.hono.client.command.kafka.KafkaBasedInternalCommandConsumer) KafkaBasedCommandResponseSender(org.eclipse.hono.client.command.kafka.KafkaBasedCommandResponseSender) ProtonBasedCommandResponseSender(org.eclipse.hono.client.command.amqp.ProtonBasedCommandResponseSender) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) EventSender(org.eclipse.hono.client.telemetry.EventSender) ProtonBasedInternalCommandConsumer(org.eclipse.hono.client.command.amqp.ProtonBasedInternalCommandConsumer) TelemetrySender(org.eclipse.hono.client.telemetry.TelemetrySender) KafkaBasedTelemetrySender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedTelemetrySender)

Example 4 with EventSender

use of org.eclipse.hono.client.telemetry.EventSender in project hono by eclipse.

the class MongoDbBasedRegistrationServiceTest method mockEventSenders.

private MessagingClientProvider<EventSender> mockEventSenders() {
    final EventSender eventSender = mock(EventSender.class);
    when(eventSender.getMessagingType()).thenReturn(MessagingType.amqp);
    when(eventSender.start()).thenReturn(Future.succeededFuture());
    when(eventSender.stop()).thenReturn(Future.succeededFuture());
    return new MessagingClientProvider<EventSender>().setClient(eventSender);
}
Also used : EventSender(org.eclipse.hono.client.telemetry.EventSender)

Example 5 with EventSender

use of org.eclipse.hono.client.telemetry.EventSender 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;
}
Also used : Buffer(io.vertx.core.buffer.Buffer) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) ProtonBasedDownstreamSender(org.eclipse.hono.client.telemetry.amqp.ProtonBasedDownstreamSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender) EventSender(org.eclipse.hono.client.telemetry.EventSender) KafkaBasedEventSender(org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender)

Aggregations

EventSender (org.eclipse.hono.client.telemetry.EventSender)10 MessagingClientProvider (org.eclipse.hono.client.util.MessagingClientProvider)6 Buffer (io.vertx.core.buffer.Buffer)4 KafkaBasedEventSender (org.eclipse.hono.client.telemetry.kafka.KafkaBasedEventSender)4 CommandResponseSender (org.eclipse.hono.client.command.CommandResponseSender)3 TelemetrySender (org.eclipse.hono.client.telemetry.TelemetrySender)3 ProtonBasedDownstreamSender (org.eclipse.hono.client.telemetry.amqp.ProtonBasedDownstreamSender)3 RegistrationAssertion (org.eclipse.hono.util.RegistrationAssertion)3 TenantObject (org.eclipse.hono.util.TenantObject)3 Vertx (io.vertx.core.Vertx)2 Map (java.util.Map)2 CommandRouterClient (org.eclipse.hono.client.command.CommandRouterClient)2 DeviceRegistrationClient (org.eclipse.hono.client.registry.DeviceRegistrationClient)2 Tenant (org.eclipse.hono.service.management.tenant.Tenant)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Span (io.opentracing.Span)1 SpanContext (io.opentracing.SpanContext)1 Tags (io.opentracing.tag.Tags)1 Context (io.vertx.core.Context)1 Future (io.vertx.core.Future)1