Skip to content

stephanprobst/aspnetcore-nats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ASP.NET Core NATS Integration

How to use

Add nuget package

dotnet add package Probst.AspNetCore.Nats

In your ASP.NET Core Startup class:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddNats(options =>
        {
            options.Url = "nats://nats:4222";
            // configure other options
        });

        services.AddMvc()
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

Inject an interface of IJsonEncodedConnection, IEncodedConnection or IConnection where you wan't to use NATS (e.g. in your Controller constructor):

    public ValueController(IJsonEncodedConnection natsConnection)
    {
        _natsConnection = natsConnection;
    }
    
    // Use it

The IJsonEncodedConnection is a convenience interface which abstracts a IEncodedConnection with built in object to bytes conversion with Newtonsoft.Json. The IEncodedConnection has also already preinitialized conversion.

NATS Project

NATS Website

Used NATS client libary

nats-io/csharp-nats

About

NATS integration for ASP.NET Core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages