use of org.eclipse.hono.commandrouter.CommandConsumerFactory in project hono by eclipse.
the class CommandRouterServiceImplTest method testRegisterCommandRouterAlsoUsingAmqpMessagingSystem.
/**
* Verifies that a command consumer gets registered in both AMQP and Kafka messaging systems if both are available
* and the tenant is configured to use Kafka.
*
* @param ctx The vert.x test context.
*/
@Test
public void testRegisterCommandRouterAlsoUsingAmqpMessagingSystem(final VertxTestContext ctx) {
// GIVEN a tenant configured to use a Kafka messaging system
final String tenantId = "tenant";
final TenantObject tenant = new TenantObject(tenantId, true);
tenant.setProperty(TenantConstants.FIELD_EXT, Map.of(TenantConstants.FIELD_EXT_MESSAGING_TYPE, MessagingType.kafka.name()));
when(tenantClient.get(eq(tenantId), any(SpanContext.class))).thenReturn(Future.succeededFuture(tenant));
// AND a commandConsumerFactoryProvider with both AMQP (see setUp()) and Kafka client providers
final CommandConsumerFactory kafkaCommandConsumerFactory = mock(CommandConsumerFactory.class);
when(kafkaCommandConsumerFactory.getMessagingType()).thenReturn(MessagingType.kafka);
when(kafkaCommandConsumerFactory.start()).thenReturn(Future.succeededFuture());
when(kafkaCommandConsumerFactory.stop()).thenReturn(Future.succeededFuture());
when(kafkaCommandConsumerFactory.createCommandConsumer(anyString(), any())).thenReturn(Future.succeededFuture());
commandConsumerFactoryProvider.setClient(kafkaCommandConsumerFactory);
// let the AMQP client consumer creation fail
when(amqpCommandConsumerFactory.createCommandConsumer(anyString(), any())).thenReturn(Future.failedFuture("expected failure"));
// WHEN registering a command consumer for the tenant
service.registerCommandConsumer(tenantId, "deviceId", "adapterInstanceId", null, NoopSpan.INSTANCE).onComplete(ctx.succeeding(res -> {
ctx.verify(() -> {
// THEN both kinds of consumer clients get used
verify(kafkaCommandConsumerFactory).createCommandConsumer(anyString(), any());
verify(amqpCommandConsumerFactory).createCommandConsumer(anyString(), any());
// and the register operation succeeds even though the AMQP client registration failed
assertThat(res.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.commandrouter.CommandConsumerFactory in project hono by eclipse.
the class Application method commandConsumerFactoryProvider.
private MessagingClientProvider<CommandConsumerFactory> commandConsumerFactoryProvider(final TenantClient tenantClient, final CommandTargetMapper commandTargetMapper) {
final MessagingClientProvider<CommandConsumerFactory> commandConsumerFactoryProvider = new MessagingClientProvider<>();
if (kafkaConsumerConfig.isConfigured() && commandResponseKafkaProducerConfig.isConfigured() && commandInternalKafkaProducerConfig.isConfigured()) {
final KafkaProducerFactory<String, Buffer> kafkaProducerFactory = CachingKafkaProducerFactory.sharedFactory(vertx);
kafkaProducerFactory.setMetricsSupport(kafkaClientMetricsSupport);
if (internalKafkaTopicCleanupService == null && commandInternalKafkaProducerConfig.isConfigured() && kafkaConsumerConfig.isConfigured() && kafkaAdminClientConfig.isConfigured() && !(adapterInstanceStatusService instanceof AdapterInstanceStatusService.UnknownStatusProvidingService)) {
internalKafkaTopicCleanupService = new InternalKafkaTopicCleanupService(vertx, adapterInstanceStatusService, kafkaAdminClientConfig);
}
commandConsumerFactoryProvider.setClient(new KafkaBasedCommandConsumerFactoryImpl(vertx, tenantClient, commandTargetMapper, kafkaProducerFactory, commandInternalKafkaProducerConfig, commandResponseKafkaProducerConfig, kafkaConsumerConfig, metrics, kafkaClientMetricsSupport, tracer, internalKafkaTopicCleanupService));
}
if (commandConsumerConnectionConfig.isHostConfigured()) {
commandConsumerFactoryProvider.setClient(new ProtonBasedCommandConsumerFactoryImpl(HonoConnection.newConnection(vertx, commandConsumerConnectionConfig, tracer), tenantClient, commandTargetMapper, metrics, SendMessageSampler.Factory.noop()));
}
return commandConsumerFactoryProvider;
}
Aggregations