Table of Contents

NatsCommandQueue Class

Definition

Namespace
Savvyio.Extensions.NATS.Commands
Assemblies
Savvyio.Extensions.NATS.dll
Source
src/Savvyio.Extensions.NATS/Commands/NatsCommandQueue.cs

Provides a NATS JetStream implementation of the IPointToPointChannel<TRequest> for command messages.

public class NatsCommandQueue : NatsMessage, IDisposable, IAsyncDisposable, IHealthCheckProvider<INatsConnection>, IPointToPointChannel<ICommand>, ISender<ICommand>, IReceiver<ICommand>
Inheritance
object
NatsCommandQueue
Implements
IHealthCheckProvider<INatsConnection>
Derived
Inherited Members

Examples

NatsCommandQueue is the NATS JetStream command queue that publishes and receives IMessage<ICommand> envelopes. Configure it with NatsCommandQueueOptions and IMarshaller to set up the connection.

using System;
using Savvyio.Commands;
using Savvyio.Extensions.NATS.Commands;
using Savvyio.Messaging;

namespace ExampleApp;

public class NatsCommandQueueConfig
{
    public static NatsCommandQueueOptions CreateOptions()
    {
        return new NatsCommandQueueOptions
        {
            NatsUrl = new Uri("nats://localhost:4222"),
            Subject = "account-commands",
            StreamName = "savvyio-commands",
            ConsumerName = "account-command-consumer",
            AutoAcknowledge = true
        };
    }

    public static IPointToPointChannel<ICommand> AsChannel(NatsCommandQueue queue) => queue;
}

Constructors

Name Description
NatsCommandQueue(IMarshaller, NatsCommandQueueOptions)

Initializes a new instance of the NatsCommandQueue class.

Methods

Name Description
CreateConsumerAsync(StreamConfig, ConsumerConfig, CancellationToken)

Creates or updates the stream and consumer used by receive operations.

CreateJetStreamContext()

Creates a NATS JetStream context used by send and receive operations.

FetchMessagesAsync(INatsJSConsumer, NatsJSFetchOpts, CancellationToken)

Fetches messages from the specified NATS JetStream consumer.

PublishMessageAsync(INatsJSContext, string, string, NatsHeaders)

Publishes a serialized message to NATS JetStream.

ReceiveAsync(Action<AsyncOptions>)

Receives command messages asynchronously from the configured NATS JetStream consumer.

SendAsync(IEnumerable<IMessage<ICommand>>, Action<AsyncOptions>)

Sends the specified command messages asynchronously to the configured NATS JetStream subject.

See Also