NatsConsumerServices

Provides consumer services for NATS.

Namespace:
KpokPatagon.Queue.Nats
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
No
Inherits from:
KpokPatagon.Queue.Nats.ServicesBase
Implements:
KpokPatagon.Queue.IConsumerServices, System.IAsyncDisposable

Constructors

NatsConsumerServices

Initializes a new instance of NatsConsumerServices.

Signature:
public Void NatsConsumerServices(logger, options)
Parameters
Name Type Summary
logger ILogger<NatsConsumerServices>
options IOptions<QueueConnectionOptions>

Methods

ConsumeFanoutAsync

Registers a callback to be invoked when a message is available on the queue, then returns while consumption continues in the background.

The onMessage callback is executed with the message body as a byte[] and the message headers as a dictionary, then the message is Ack; If an error occurred the onError callback is executed if provided, then the message is Nack and requeued only if the onError callback returned true.

Signature:
public Task ConsumeFanoutAsync(fanout, onMessage, onError, cancellationToken)
Parameters
Name Type Summary
fanout String The name of the fanout.
onMessage Action<Byte[], IDictionary> The callback action to process the message.
onError Func<Exception, Boolean> An error callback action called when an error occurred while processing a message.
cancellationToken CancellationToken A cancellation token that stops the background consumer.

ConsumeFanoutAsync

Setup a callback to be invoked when a message is available on the queue.

If the message is successfully deserialized the onMessage callback is executed then the message is Ack; If an error occurred the onError callback is executed if provided, then the message is Nack and requeued only if the onError callback returned true.

Signature:
public Task ConsumeFanoutAsync<T>(fanout, onMessage, onError, serializer, cancellationToken)
Parameters
Name Type Summary
fanout String The name of the fanout.
onMessage Action<T, IDictionary> The callback action to process the message.
onError Func<Exception, Boolean> An error callback action called when an error occurred while processing a message.
serializer IMessageSerializer A service to serialize the message.
cancellationToken CancellationToken A cancellation token.

ConsumeWorkQueueAsync

Setup a callback to be invoked when a message is available on the queue.

The onMessage callback is executed with the message body as a byte[] and the message headers as a dictionary, then the message is Ack; If an error occurred the onError callback is executed if provided, then the message is Nack and requeued only if the onError callback returned true.

Signature:
public Task ConsumeWorkQueueAsync(queue, onMessage, onError, cancellationToken)
Parameters
Name Type Summary
queue String The name of the queue.
onMessage Action<Byte[], IDictionary> The callback action to process the message.
onError Func<Exception, Boolean> An error callback action called when an error occurred while processing a message.
cancellationToken CancellationToken A cancellation token.

ConsumeWorkQueueAsync

Setup a callback to be invoked when a message is available on the queue.

If the message is successfully deserialized the onMessage callback is executed then the message is Ack; If an error occurred the onError callback is executed if provided, then the message is Nack and requeued only if the onError callback returned true.

Signature:
public Task ConsumeWorkQueueAsync<T>(queue, onMessage, onError, serializer, cancellationToken)
Parameters
Name Type Summary
queue String The name of the queue.
onMessage Action<T, IDictionary> The callback action to process the message.
onError Func<Exception, Boolean> An error callback action called when an error occurred while processing a message.
serializer IMessageSerializer A service to serialize the message.
cancellationToken CancellationToken A cancellation token.