use of org.eclipse.hono.client.telemetry.EventSender in project hono by eclipse.
the class ProtocolAdapterMockSupport method createEventSenderMock.
private EventSender createEventSenderMock() {
final EventSender sender = mock(EventSender.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.EventSender in project hono by eclipse.
the class DeviceAndGatewayAutoProvisionerTest method init.
/**
* Initializes common fixture.
*
* @throws GeneralSecurityException if the self signed certificate cannot be created.
* @throws IOException if the self signed certificate cannot be read.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void init() throws GeneralSecurityException, IOException {
tenantId = UUID.randomUUID().toString();
deviceId = UUID.randomUUID().toString();
commonName = UUID.randomUUID().toString();
final SelfSignedCertificate ssc = SelfSignedCertificate.create(String.format("%s,OU=Hono,O=Eclipse", commonName));
cert = (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new FileInputStream(ssc.certificatePath()));
subjectDn = cert.getSubjectX500Principal().getName(X500Principal.RFC2253);
final TrustedCertificateAuthority trustedCertificateAuthority = new TrustedCertificateAuthority().setCertificate(cert.getEncoded());
tenant = new Tenant().setTrustedCertificateAuthorities(List.of(trustedCertificateAuthority));
deviceManagementService = mock(DeviceManagementService.class);
credentialsManagementService = mock(CredentialsManagementService.class);
sender = mock(EventSender.class);
when(sender.getMessagingType()).thenReturn(MessagingType.amqp);
when(sender.sendEvent(any(TenantObject.class), any(RegistrationAssertion.class), anyString(), any(), any(Map.class), any())).thenReturn(Future.succeededFuture());
deviceAndGatewayAutoProvisioner = new DeviceAndGatewayAutoProvisioner(mock(Vertx.class), deviceManagementService, credentialsManagementService, new MessagingClientProvider<EventSender>().setClient(sender));
}
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;
}
use of org.eclipse.hono.client.telemetry.EventSender 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);
}
use of org.eclipse.hono.client.telemetry.EventSender in project hono by eclipse.
the class AbstractAutoProvisioningEventSender method sendAutoProvisioningEvent.
/**
* Send an auto-provisioning event with content type
* {@value EventConstants#CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION}.
*
* @param tenantId The tenant identifier.
* @param tenant The tenant information.
* @param deviceId The device identifier.
* @param gatewayId The gateway identifier if an edge device is being auto-provisioned.
* @param span The active OpenTracing span for this operation. It is not to be closed in this method! An
* implementation should log (error) events on this span and it may set tags and use this span as the
* parent for any spans created in this method.
* @return A future indicating the outcome of the operation. The future will be succeeded if the auto-provisioning
* event is sent successfully.
* @throws NullPointerException if any of the parameters except gateway id is {@code null}.
* @see "https://www.eclipse.org/hono/docs/api/event/#device-provisioning-notification"
*/
protected Future<Void> sendAutoProvisioningEvent(final String tenantId, final Tenant tenant, final String deviceId, final String gatewayId, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(span);
// TODO to remove once able to send events without providing an argument of type TenantObject
final TenantObject tenantConfig = DeviceRegistryUtils.convertTenant(tenantId, tenant).mapTo(TenantObject.class);
final EventSender eventSender = eventSenderProvider.getClient(tenantConfig);
return eventSender.sendEvent(tenantConfig, new RegistrationAssertion(deviceId), EventConstants.CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION, null, assembleAutoProvisioningEventProperties(tenantId, gatewayId), span.context()).onSuccess(ok -> {
span.log("sent auto-provisioning notification");
LOG.debug("sent auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
}).onFailure(t -> {
TracingHelper.logError(span, "error sending auto-provisioning notification", t);
LOG.warn("error sending auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
});
}
Aggregations