Package io.micronaut.nats.intercept
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 Summary
ConstructorDescriptionNatsConsumerAdvice
(io.micronaut.context.BeanContext beanContext, NatsBinderRegistry binderRegistry, NatsMessageSerDesRegistry serDesRegistry, NatsListenerExceptionHandler exceptionHandler, io.micronaut.runtime.ApplicationConfiguration applicationConfiguration) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
@NonNull io.nats.client.Consumer
getConsumer
(@NonNull String id) Returns the subscription by given id.The IDs of the available consumers.@NonNull Set<io.nats.client.Subscription>
getConsumerSubscription
(@NonNull String id) Returns a managed Consumer's subscriptions.io.nats.client.Subscription
newSubscription
(@NonNull String connectionName, @NonNull String subject, @Nullable String queue) Create a new subscription from the given connection name.io.nats.client.Subscription
newSubscription
(@NonNull String subject, @Nullable String queue) Create a new subscription with the default connection.void
process
(io.micronaut.inject.BeanDefinition<?> beanDefinition, io.micronaut.inject.ExecutableMethod<?, ?> method)
-
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 contextbinderRegistry
- The registry to bind arguments to the methodserDesRegistry
- The serialization/deserialization registryexceptionHandler
- The exception handler to use if the consumer isn't a handlerapplicationConfiguration
- The application configuration
-
-
Method Details
-
process
public void process(io.micronaut.inject.BeanDefinition<?> beanDefinition, io.micronaut.inject.ExecutableMethod<?, ?> method) -
close
@PreDestroy public void close()- Specified by:
close
in interfaceAutoCloseable
-
getConsumer
Description copied from interface:ConsumerRegistry
Returns the subscription by given id.- Specified by:
getConsumer
in interfaceConsumerRegistry
- Parameters:
id
-String
The id of the listener- Returns:
- The consumer
-
getConsumerIds
Description copied from interface:ConsumerRegistry
The IDs of the available consumers.- Specified by:
getConsumerIds
in interfaceConsumerRegistry
- 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 interfaceConsumerRegistry
- 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 interfaceConsumerRegistry
- 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 interfaceConsumerRegistry
- Parameters:
connectionName
-String
subject
-String
queue
-String
optional- Returns:
- subscription
Subscription
-