NsqSharp.Async 1.0.3

dotnet add package NsqSharp.Async --version 1.0.3
                    
NuGet\Install-Package NsqSharp.Async -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NsqSharp.Async" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NsqSharp.Async" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="NsqSharp.Async" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NsqSharp.Async --version 1.0.3
                    
#r "nuget: NsqSharp.Async, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NsqSharp.Async@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NsqSharp.Async&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=NsqSharp.Async&version=1.0.3
                    
Install as a Cake Tool

NsqSharp.Async

License  NuGet version  Nuget

A .NET client library for NSQ, a realtime distributed messaging platform.

Check out this slide deck for a quick intro to NSQ.

Watch Spray Some NSQ On It by co-author Matt Reiferson for an under 30-minute intro to NSQ as a messaging platform.

Project Status

  • Rewrite with async version.
  • Support .NET 8.0+.

Quick Install

NsqSharp is a client library that talks to the nsqd (message queue) and nsqlookupd (topic discovery service). See the slides above for more information about their roles.

You can also build these files from source: https://github.com/nsqio/nsq (official). Or you can use official docker image: https://nsq.io/deployment/docker.html .

C# Examples

dotnet add package NsqSharp.Async --version 1.0.1

Simple Producer
static void Main()  
{
    var producer = new Producer("127.0.0.1:4150");
    producer.Publish("test-topic-name", "Hello!");

    Console.WriteLine("Enter your message (blank line to quit):");
    string line = Console.ReadLine();
    while (!string.IsNullOrEmpty(line))
    {
        producer.Publish("test-topic-name", line, fireAndForgot: false);
        line = Console.ReadLine();
    }
    producer.Stop();
}

// async version
static async Task Main()  
{
    var producer = new Producer("127.0.0.1:4150");
    await producer.PublishAsync("test-topic-name", "Hello!");
    producer.Stop();
}

Simple Consumer
static void Main()  
{
    // Create a new Consumer for each topic/channel
    var consumer = new Consumer("test-topic-name", "channel-name");
    consumer.AddHandler(new MessageHandler());
    consumer.ConnectToNsqLookupdAsync(new string[] {"127.0.0.1:4161"}).Wait();

    Console.WriteLine("Listening for messages. If this is the first execution, it " +
                        "could take up to 60s for topic producers to be discovered.");
    Console.WriteLine("Press enter to stop...");
    Console.ReadLine();

    consumer.Stop();
}

//async version
static async Task Main()  
{
    // Create a new Consumer for each topic/channel
    var appCts = new CancellationTokenSource();
    var appCtx = appCts.Token;
    var consumer = new Consumer("test-topic-name", "channel-name");
    consumer.AddHandler(new MessageHandler());
    await consumer.ConnectToNsqLookupdAsync(new string[] {"127.0.0.1:4161"}, appCtx);

    Console.WriteLine("Listening for messages. If this is the first execution, it " +
                        "could take up to 60s for topic producers to be discovered.");
    Console.WriteLine("Press enter to stop...");
    Console.ReadLine();
    // process the graceful exit if you get your context exiting ...
    // stop consumer
    await consumer.StopAsync();
}

public class MessageHandler : IHandler
{
    public bool RunAsAsync => false; // specify this property to indicate use async or sync message handle

    public Task HandleMessageAsync(IMessage message, CancellationToken token)
    {
        
    }

    public void HandleMessage(IMessage message)
    {
        string msg = Encoding.UTF8.GetString(message.Body);
        Console.WriteLine(msg);
        // if not specify, the message will automatically set as finish.

        // the following operation is write to the internal queue 
        // hence no need to wait message submit its final state.

        // message.Finish() 
        // message.Touch() 

        // message.ReQueue(delayTime)
        // message.ReQueueWithoutBackOff(delayTime)
    }

    public void LogFailedMessage(IMessage message)
    {
        
    }
}

NsqSharp Project Goals

  • Structurally similar to the official go-nsq client.
  • Provide similar behavior and semantics as the official package.

Pull Requests

Pull requests and issues are very welcome and appreciated.

When submitting a pull request please keep in mind we're trying to stay as close to go-nsq as possible. This sometimes means writing C# which looks more like Go and follows their file layout. Code in the NsqSharp.Bus namespace should follow C# conventions and more or less look like other code in this namespace.

License

This project is open source and released under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 285 11/11/2025
1.0.1 196 11/6/2025