Class NatsConsumerAdvice

java.lang.Object
io.micronaut.nats.intercept.NatsConsumerAdvice
All Implemented Interfaces:
io.micronaut.context.processor.AnnotationProcessor<Subject,io.micronaut.inject.ExecutableMethod<?,?>>, io.micronaut.context.processor.ExecutableMethodProcessor<Subject>, ConsumerRegistry, AutoCloseable

@Singleton @Bean(preDestroy="close") public class NatsConsumerAdvice extends Object implements io.micronaut.context.processor.ExecutableMethodProcessor<Subject>, AutoCloseable, ConsumerRegistry
An ExecutableMethodProcessor that will process all beans annotated with NatsListener. It creates and subscribes the relevant methods as consumers to Nats subjects.
Since:
1.0.0
Author:
Joachim Grimm
  • Constructor Details

    • NatsConsumerAdvice

      public NatsConsumerAdvice(io.micronaut.context.BeanContext beanContext, NatsBinderRegistry binderRegistry, NatsMessageSerDesRegistry serDesRegistry, NatsListenerExceptionHandler exceptionHandler, io.micronaut.runtime.ApplicationConfiguration applicationConfiguration)
      Default constructor.
      Parameters:
      beanContext - The bean context
      binderRegistry - The registry to bind arguments to the method
      serDesRegistry - The serialization/deserialization registry
      exceptionHandler - The exception handler to use if the consumer isn't a handler
      applicationConfiguration - The application configuration
  • Method Details

    • process

      public void process(io.micronaut.inject.BeanDefinition<?> beanDefinition, io.micronaut.inject.ExecutableMethod<?,?> method)
      Specified by:
      process in interface io.micronaut.context.processor.AnnotationProcessor<Subject,io.micronaut.inject.ExecutableMethod<?,?>>
      Specified by:
      process in interface io.micronaut.context.processor.ExecutableMethodProcessor<Subject>
    • close

      @PreDestroy public void close()
      Specified by:
      close in interface AutoCloseable
    • getConsumer

      @NonNull public @NonNull io.nats.client.Consumer getConsumer(@NonNull @NonNull String id)
      Description copied from interface: ConsumerRegistry
      Returns the subscription by given id.
      Specified by:
      getConsumer in interface ConsumerRegistry
      Parameters:
      id - String The id of the listener
      Returns:
      The consumer
    • getConsumerIds

      @NonNull public @NonNull Set<String> getConsumerIds()
      Description copied from interface: ConsumerRegistry
      The IDs of the available consumers.
      Specified by:
      getConsumerIds in interface ConsumerRegistry
      Returns:
      The consumers
    • getConsumerSubscription

      @NonNull public @NonNull Set<io.nats.client.Subscription> getConsumerSubscription(@NonNull @NonNull String id)
      Description copied from interface: ConsumerRegistry
      Returns a managed Consumer's subscriptions.
      Specified by:
      getConsumerSubscription in interface ConsumerRegistry
      Parameters:
      id - The id of the producer.
      Returns:
      The consumer subscription
    • newSubscription

      public io.nats.client.Subscription newSubscription(@NonNull @NonNull String subject, @Nullable @Nullable String queue)
      Description copied from interface: ConsumerRegistry
      Create a new subscription with the default connection.
      Specified by:
      newSubscription in interface ConsumerRegistry
      Parameters:
      subject - String
      queue - String optional
      Returns:
      subscription Subscription
    • newSubscription

      public io.nats.client.Subscription newSubscription(@NonNull @NonNull String connectionName, @NonNull @NonNull String subject, @Nullable @Nullable String queue)
      Description copied from interface: ConsumerRegistry
      Create a new subscription from the given connection name.
      Specified by:
      newSubscription in interface ConsumerRegistry
      Parameters:
      connectionName - String
      subject - String
      queue - String optional
      Returns:
      subscription Subscription