Table of Contents

Class NatsCommandQueue<TMarker>

Namespace
Savvyio.Extensions.DependencyInjection.NATS.Commands
Assembly
Savvyio.Extensions.DependencyInjection.NATS.dll

Provides a default implementation of the NatsMessage class for messages holding an ICommand implementation.

public class NatsCommandQueue<TMarker> : NatsCommandQueue, IDisposable, IAsyncDisposable, IHealthCheckProvider<INatsConnection>, IPointToPointChannel<ICommand, TMarker>, IPointToPointChannel<ICommand>, ISender<ICommand, TMarker>, ISender<ICommand>, IReceiver<ICommand, TMarker>, IReceiver<ICommand>, IDependencyInjectionMarker<TMarker>

Type Parameters

TMarker
Inheritance
NatsCommandQueue<TMarker>
Implements
IHealthCheckProvider<INatsConnection>
ISender<ICommand, TMarker>
Inherited Members

Examples

NatsCommandQueue<TMarker> is the DI-registered NATS command queue with a lifetime marker. Register it with AddNatsCommandQueue and resolve it as NatsCommandQueue or IPointToPointChannel<ICommand>.

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

namespace ExampleApp;

public static class NatsQueueUsage
{
    public static NatsCommandQueue GetQueue(IServiceProvider provider)
    {
        return provider.GetRequiredService<NatsCommandQueue>();
    }

    public static IPointToPointChannel<ICommand> GetChannel(IServiceProvider provider)
    {
        return provider.GetRequiredService<IPointToPointChannel<ICommand>>();
    }

    public static IServiceCollection Register(IServiceCollection services)
    {
        services.AddSavvyIO();
        services.AddNatsCommandQueue(o => { o.Subject = "commands"; });
        return services;
    }
}

Constructors

NatsCommandQueue(IMarshaller, NatsCommandQueueOptions<TMarker>)

Initializes a new instance of the NatsCommandQueue<TMarker> class.

public NatsCommandQueue(IMarshaller marshaller, NatsCommandQueueOptions<TMarker> options)

Parameters

marshaller IMarshaller

The marshaller used for serializing and deserializing messages.

options NatsCommandQueueOptions<TMarker>

The options used to configure the NATS command queue.

Exceptions

ArgumentNullException

marshaller cannot be null -or- options cannot be null.

ArgumentException

options are not in a valid state.

See Also

NatsCommandQueue<TMarker>
IPointToPointChannel<TRequest, TMarker>