Search in sources :

Example 1 with NotificationSender

use of org.eclipse.hono.notification.NotificationSender in project hono by eclipse.

the class Application method doStart.

@Override
protected void doStart() {
    if (!(authenticationService instanceof Verticle)) {
        throw new IllegalStateException("Authentication service must be a vert.x Verticle");
    }
    LOG.info("adding common tags to meter registry");
    meterRegistry.config().commonTags(MetricsTags.forService(Constants.SERVICE_NAME_DEVICE_REGISTRY));
    LOG.info("deploying {} {} instances ...", appConfig.getMaxInstances(), getComponentName());
    final CompletableFuture<Void> startup = new CompletableFuture<>();
    // deploy authentication service (once only)
    final Promise<String> authServiceDeploymentTracker = Promise.promise();
    vertx.deployVerticle((Verticle) authenticationService, authServiceDeploymentTracker);
    // deploy notification sender (once only)
    final Promise<String> notificationSenderDeploymentTracker = Promise.promise();
    vertx.deployVerticle(new WrappedLifecycleComponentVerticle(notificationSender), notificationSenderDeploymentTracker);
    // deploy AMQP 1.0 server
    final Promise<String> amqpServerDeploymentTracker = Promise.promise();
    vertx.deployVerticle(() -> amqpServerFactory.newServer(), new DeploymentOptions().setInstances(appConfig.getMaxInstances()), amqpServerDeploymentTracker);
    // deploy HTTP server
    final Promise<String> httpServerDeploymentTracker = Promise.promise();
    vertx.deployVerticle(() -> httpServerFactory.newServer(), new DeploymentOptions().setInstances(appConfig.getMaxInstances()), httpServerDeploymentTracker);
    CompositeFuture.all(authServiceDeploymentTracker.future(), notificationSenderDeploymentTracker.future(), amqpServerDeploymentTracker.future(), httpServerDeploymentTracker.future()).onSuccess(ok -> registerHealthCheckProvider(authenticationService)).compose(s -> healthCheckServer.start()).onSuccess(ok -> startup.complete(null)).onFailure(t -> startup.completeExceptionally(t));
    startup.join();
}
Also used : NotificationSender(org.eclipse.hono.notification.NotificationSender) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) AuthenticationService(org.eclipse.hono.service.auth.AuthenticationService) MetricsTags(org.eclipse.hono.service.metric.MetricsTags) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Verticle(io.vertx.core.Verticle) Constants(org.eclipse.hono.util.Constants) Inject(javax.inject.Inject) AbstractServiceApplication(org.eclipse.hono.service.quarkus.AbstractServiceApplication) CompositeFuture(io.vertx.core.CompositeFuture) DeploymentOptions(io.vertx.core.DeploymentOptions) ApplicationScoped(javax.enterprise.context.ApplicationScoped) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) Verticle(io.vertx.core.Verticle) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) CompletableFuture(java.util.concurrent.CompletableFuture) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) DeploymentOptions(io.vertx.core.DeploymentOptions)

Example 2 with NotificationSender

use of org.eclipse.hono.notification.NotificationSender in project hono by eclipse.

the class Application method doStart.

@Override
protected void doStart() {
    if (!(authenticationService instanceof Verticle)) {
        throw new IllegalStateException("Authentication service must be a vert.x Verticle");
    }
    LOG.info("adding common tags to meter registry");
    meterRegistry.config().commonTags(MetricsTags.forService(Constants.SERVICE_NAME_DEVICE_REGISTRY));
    LOG.info("deploying {} {} instances ...", appConfig.getMaxInstances(), getComponentName());
    final CompletableFuture<Void> startup = new CompletableFuture<>();
    // deploy authentication service (once only)
    final Promise<String> authServiceDeploymentTracker = Promise.promise();
    vertx.deployVerticle((Verticle) authenticationService, authServiceDeploymentTracker);
    // deploy notification sender (once only)
    final Promise<String> notificationSenderDeploymentTracker = Promise.promise();
    vertx.deployVerticle(new WrappedLifecycleComponentVerticle(notificationSender), notificationSenderDeploymentTracker);
    // deploy AMQP 1.0 server
    final Promise<String> amqpServerDeploymentTracker = Promise.promise();
    vertx.deployVerticle(() -> amqpServerFactory.newServer(), new DeploymentOptions().setInstances(appConfig.getMaxInstances()), amqpServerDeploymentTracker);
    // deploy HTTP server
    final Promise<String> httpServerDeploymentTracker = Promise.promise();
    vertx.deployVerticle(() -> httpServerFactory.newServer(), new DeploymentOptions().setInstances(appConfig.getMaxInstances()), httpServerDeploymentTracker);
    CompositeFuture.all(authServiceDeploymentTracker.future(), notificationSenderDeploymentTracker.future(), amqpServerDeploymentTracker.future(), httpServerDeploymentTracker.future()).onSuccess(ok -> registerHealthCheckProvider(authenticationService)).compose(s -> healthCheckServer.start()).onSuccess(ok -> startup.complete(null)).onFailure(t -> startup.completeExceptionally(t));
    startup.join();
}
Also used : NotificationSender(org.eclipse.hono.notification.NotificationSender) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) AuthenticationService(org.eclipse.hono.service.auth.AuthenticationService) MetricsTags(org.eclipse.hono.service.metric.MetricsTags) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Verticle(io.vertx.core.Verticle) Constants(org.eclipse.hono.util.Constants) Inject(javax.inject.Inject) AbstractServiceApplication(org.eclipse.hono.service.quarkus.AbstractServiceApplication) CompositeFuture(io.vertx.core.CompositeFuture) DeploymentOptions(io.vertx.core.DeploymentOptions) ApplicationScoped(javax.enterprise.context.ApplicationScoped) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) Verticle(io.vertx.core.Verticle) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) CompletableFuture(java.util.concurrent.CompletableFuture) WrappedLifecycleComponentVerticle(org.eclipse.hono.util.WrappedLifecycleComponentVerticle) DeploymentOptions(io.vertx.core.DeploymentOptions)

Example 3 with NotificationSender

use of org.eclipse.hono.notification.NotificationSender in project hono by eclipse.

the class NotificationSenderProducer method notificationSender.

@Produces
@Singleton
NotificationSender notificationSender(final Vertx vertx, final Tracer tracer, final HealthCheckServer healthCheckServer, @Named("amqp-messaging-network") final ClientConfigProperties downstreamSenderConfig, final NotificationKafkaProducerConfigProperties kafkaProducerConfig) {
    final NotificationSender notificationSender;
    if (kafkaProducerConfig.isConfigured()) {
        notificationSender = new KafkaBasedNotificationSender(CachingKafkaProducerFactory.sharedFactory(vertx), kafkaProducerConfig);
    } else {
        notificationSender = new ProtonBasedNotificationSender(HonoConnection.newConnection(vertx, downstreamSenderConfig, tracer));
    }
    if (notificationSender instanceof ServiceClient) {
        healthCheckServer.registerHealthCheckResources(ServiceClientAdapter.forClient((ServiceClient) notificationSender));
    }
    NotificationConstants.DEVICE_REGISTRY_NOTIFICATION_TYPES.forEach(notificationType -> {
        NotificationEventBusSupport.registerConsumer(vertx, notificationType, notificationSender::publish);
    });
    return notificationSender;
}
Also used : NotificationSender(org.eclipse.hono.notification.NotificationSender) ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) ServiceClient(org.eclipse.hono.client.util.ServiceClient) ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 4 with NotificationSender

use of org.eclipse.hono.notification.NotificationSender in project hono by eclipse.

the class NotificationSenderProducer method notificationSender.

@Produces
@Singleton
NotificationSender notificationSender(final Vertx vertx, final Tracer tracer, final HealthCheckServer healthCheckServer, @Named("amqp-messaging-network") final ClientConfigProperties downstreamSenderConfig, final NotificationKafkaProducerConfigProperties kafkaProducerConfig) {
    final NotificationSender notificationSender;
    if (kafkaProducerConfig.isConfigured()) {
        notificationSender = new KafkaBasedNotificationSender(CachingKafkaProducerFactory.sharedFactory(vertx), kafkaProducerConfig);
    } else {
        notificationSender = new ProtonBasedNotificationSender(HonoConnection.newConnection(vertx, downstreamSenderConfig, tracer));
    }
    if (notificationSender instanceof ServiceClient) {
        healthCheckServer.registerHealthCheckResources(ServiceClientAdapter.forClient((ServiceClient) notificationSender));
    }
    NotificationConstants.DEVICE_REGISTRY_NOTIFICATION_TYPES.forEach(notificationType -> {
        NotificationEventBusSupport.registerConsumer(vertx, notificationType, notificationSender::publish);
    });
    return notificationSender;
}
Also used : NotificationSender(org.eclipse.hono.notification.NotificationSender) ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) ServiceClient(org.eclipse.hono.client.util.ServiceClient) ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton)

Example 5 with NotificationSender

use of org.eclipse.hono.notification.NotificationSender in project hono by eclipse.

the class ApplicationConfig method notificationSender.

/**
 * Exposes a notification sender.
 *
 * @return The bean instance.
 */
@Bean
@Profile(Profiles.PROFILE_REGISTRY_MANAGEMENT)
public NotificationSender notificationSender() {
    final NotificationSender notificationSender;
    final var kafkaProducerConfig = notificationKafkaProducerConfig();
    if (kafkaProducerConfig.isConfigured()) {
        notificationSender = new KafkaBasedNotificationSender(CachingKafkaProducerFactory.sharedFactory(vertx()), kafkaProducerConfig);
    } else {
        notificationSender = new ProtonBasedNotificationSender(HonoConnection.newConnection(vertx(), downstreamSenderConfig(), tracer()));
    }
    if (notificationSender instanceof ServiceClient) {
        healthCheckServer().registerHealthCheckResources(ServiceClientAdapter.forClient((ServiceClient) notificationSender));
    }
    NotificationConstants.DEVICE_REGISTRY_NOTIFICATION_TYPES.forEach(notificationType -> {
        NotificationEventBusSupport.registerConsumer(vertx(), notificationType, notificationSender::publish);
    });
    return notificationSender;
}
Also used : ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) NotificationSender(org.eclipse.hono.notification.NotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) KafkaBasedNotificationSender(org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender) ServiceClient(org.eclipse.hono.client.util.ServiceClient) ProtonBasedNotificationSender(org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender) Profile(org.springframework.context.annotation.Profile) ObjectFactoryCreatingFactoryBean(org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

NotificationSender (org.eclipse.hono.notification.NotificationSender)5 ProtonBasedNotificationSender (org.eclipse.hono.client.notification.amqp.ProtonBasedNotificationSender)3 KafkaBasedNotificationSender (org.eclipse.hono.client.notification.kafka.KafkaBasedNotificationSender)3 ServiceClient (org.eclipse.hono.client.util.ServiceClient)3 CompositeFuture (io.vertx.core.CompositeFuture)2 DeploymentOptions (io.vertx.core.DeploymentOptions)2 Promise (io.vertx.core.Promise)2 Verticle (io.vertx.core.Verticle)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 AuthenticationService (org.eclipse.hono.service.auth.AuthenticationService)2 MetricsTags (org.eclipse.hono.service.metric.MetricsTags)2 AbstractServiceApplication (org.eclipse.hono.service.quarkus.AbstractServiceApplication)2 Constants (org.eclipse.hono.util.Constants)2 WrappedLifecycleComponentVerticle (org.eclipse.hono.util.WrappedLifecycleComponentVerticle)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2