Class NatsEventBus
- Namespace
- Savvyio.Extensions.NATS.EventDriven
- Assembly
- Savvyio.Extensions.NATS.dll
Provides a NATS implementation of the IPublishSubscribeChannel<TRequest> for integration event messages.
public class NatsEventBus : NatsMessage, IDisposable, IAsyncDisposable, IHealthCheckProvider<INatsConnection>, IPublishSubscribeChannel<IIntegrationEvent>, IPublisher<IIntegrationEvent>, ISubscriber<IIntegrationEvent>
- Inheritance
-
NatsEventBus
- Implements
-
IHealthCheckProvider<INatsConnection>
- Derived
- Inherited Members
Constructors
NatsEventBus(IMarshaller, NatsEventBusOptions)
Initializes a new instance of the NatsEventBus class.
public NatsEventBus(IMarshaller marshaller, NatsEventBusOptions options)
Parameters
marshallerIMarshallerThe marshaller used for serializing and deserializing messages.
optionsNatsEventBusOptionsThe NatsEventBusOptions used to configure this instance.
Exceptions
- ArgumentNullException
marshallercannot be null - or -optionscannot be null.- ArgumentException
optionsare not in a valid state.
Methods
PublishAsync(IMessage<IIntegrationEvent>, Action<AsyncOptions>)
Publishes the specified integration event message asynchronously to the configured NATS subject.
public Task PublishAsync(IMessage<IIntegrationEvent> message, Action<AsyncOptions> setup = null)
Parameters
messageIMessage<IIntegrationEvent>The message to publish.
setupAction<AsyncOptions>The AsyncOptions which may be configured.
Returns
SubscribeAsync(Func<IMessage<IIntegrationEvent>, CancellationToken, Task>, Action<SubscribeAsyncOptions>)
Subscribes to integration event messages from the configured NATS subject and invokes the specified asynchronous handler for each received message.
public Task SubscribeAsync(Func<IMessage<IIntegrationEvent>, CancellationToken, Task> asyncHandler, Action<SubscribeAsyncOptions> setup = null)
Parameters
asyncHandlerFunc<IMessage<IIntegrationEvent>, CancellationToken, Task>The function delegate that will handle the message.
setupAction<SubscribeAsyncOptions>The SubscribeAsyncOptions which may be configured.