Search in sources :

Example 6 with EventSender

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;
}
Also used : EventSender(org.eclipse.hono.client.telemetry.EventSender)

Example 7 with EventSender

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));
}
Also used : TenantObject(org.eclipse.hono.util.TenantObject) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) Tenant(org.eclipse.hono.service.management.tenant.Tenant) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) EventSender(org.eclipse.hono.client.telemetry.EventSender) TrustedCertificateAuthority(org.eclipse.hono.service.management.tenant.TrustedCertificateAuthority) CredentialsManagementService(org.eclipse.hono.service.management.credentials.CredentialsManagementService) Map(java.util.Map) FileInputStream(java.io.FileInputStream) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 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)

Example 9 with EventSender

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);
}
Also used : Context(io.vertx.core.Context) VertxTestContext(io.vertx.junit5.VertxTestContext) TelemetryExecutionContext(org.eclipse.hono.util.TelemetryExecutionContext) SpanContext(io.opentracing.SpanContext) CommandRouterClient(org.eclipse.hono.client.command.CommandRouterClient) ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) CommandConsumerFactory(org.eclipse.hono.client.command.CommandConsumerFactory) DeviceRegistrationClient(org.eclipse.hono.client.registry.DeviceRegistrationClient) Vertx(io.vertx.core.Vertx) CredentialsClient(org.eclipse.hono.client.registry.CredentialsClient) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) CommandResponseSender(org.eclipse.hono.client.command.CommandResponseSender) TenantClient(org.eclipse.hono.client.registry.TenantClient) EventSender(org.eclipse.hono.client.telemetry.EventSender) TelemetrySender(org.eclipse.hono.client.telemetry.TelemetrySender) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with EventSender

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);
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Lifecycle(org.eclipse.hono.util.Lifecycle) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Constants(org.eclipse.hono.util.Constants) Tags(io.opentracing.tag.Tags) Tenant(org.eclipse.hono.service.management.tenant.Tenant) DeviceManagementService(org.eclipse.hono.service.management.device.DeviceManagementService) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) Device(org.eclipse.hono.service.management.device.Device) Logger(org.slf4j.Logger) EventSender(org.eclipse.hono.client.telemetry.EventSender) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) Vertx(io.vertx.core.Vertx) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) DeviceStatus(org.eclipse.hono.service.management.device.DeviceStatus) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) Objects(java.util.Objects) Optional(java.util.Optional) Span(io.opentracing.Span) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) EventSender(org.eclipse.hono.client.telemetry.EventSender)

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