use of org.eclipse.hono.client.telemetry.TelemetrySender 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());
}
use of org.eclipse.hono.client.telemetry.TelemetrySender 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.TelemetrySender in project hono by eclipse.
the class ProtocolAdapterMockSupport method createTelemetrySenderMock.
private TelemetrySender createTelemetrySenderMock() {
final TelemetrySender sender = mock(TelemetrySender.class);
when(sender.getMessagingType()).thenReturn(MessagingType.amqp);
when(sender.start()).thenReturn(Future.succeededFuture());
when(sender.stop()).thenReturn(Future.succeededFuture());
return sender;
}
use of org.eclipse.hono.client.telemetry.TelemetrySender in project hono by eclipse.
the class AbstractProtocolAdapterBaseTest method setup.
/**
* Sets up the fixture.
*/
@BeforeEach
public void setup() {
tenantClient = mock(TenantClient.class);
when(tenantClient.start()).thenReturn(Future.succeededFuture());
registrationClient = mock(DeviceRegistrationClient.class);
when(registrationClient.start()).thenReturn(Future.succeededFuture());
credentialsClient = mock(CredentialsClient.class);
when(credentialsClient.start()).thenReturn(Future.succeededFuture());
amqpTelemetrySender = mockMessagingClient(TelemetrySender.class, MessagingType.amqp);
when(amqpTelemetrySender.start()).thenReturn(Future.succeededFuture());
kafkaTelemetrySender = mockMessagingClient(TelemetrySender.class, MessagingType.kafka);
when(kafkaTelemetrySender.start()).thenReturn(Future.succeededFuture());
amqpEventSender = mockMessagingClient(EventSender.class, MessagingType.amqp);
when(amqpEventSender.start()).thenReturn(Future.succeededFuture());
kafkaEventSender = mockMessagingClient(EventSender.class, MessagingType.kafka);
when(kafkaEventSender.start()).thenReturn(Future.succeededFuture());
commandConsumerFactory = mock(CommandConsumerFactory.class);
when(commandConsumerFactory.start()).thenReturn(Future.succeededFuture());
amqpCommandResponseSender = mockMessagingClient(CommandResponseSender.class, MessagingType.amqp);
when(amqpCommandResponseSender.start()).thenReturn(Future.succeededFuture());
kafkaCommandResponseSender = mockMessagingClient(CommandResponseSender.class, MessagingType.kafka);
when(kafkaCommandResponseSender.start()).thenReturn(Future.succeededFuture());
final var telemetrySenderProvider = new MessagingClientProvider<TelemetrySender>().setClient(amqpTelemetrySender).setClient(kafkaTelemetrySender);
final var eventSenderProvider = new MessagingClientProvider<EventSender>().setClient(amqpEventSender).setClient(kafkaEventSender);
final var commandResponseSenderProvider = new MessagingClientProvider<CommandResponseSender>().setClient(amqpCommandResponseSender).setClient(kafkaCommandResponseSender);
messagingClientProviders = new MessagingClientProviders(telemetrySenderProvider, eventSenderProvider, commandResponseSenderProvider);
commandRouterClient = mock(CommandRouterClient.class);
when(commandRouterClient.start()).thenReturn(Future.succeededFuture());
properties = new ProtocolAdapterProperties();
adapter = newProtocolAdapter(properties, ADAPTER_NAME);
setCollaborators(adapter);
vertx = mock(Vertx.class);
VertxMockSupport.runTimersImmediately(vertx);
context = mock(Context.class);
adapter.init(vertx, context);
}
Aggregations