Skip to content

Repository files navigation

PureNSQSharp

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

NuGet PackagePureNSQSharp

Quick Install

PureNSQSharp is a client library that talks to the nsqd (message queue) and nsqlookupd (topic discovery service).

nsqlookupd
nsqd -lookupd-tcp-address=127.0.0.1:4160

Simple Producer

usingSystem;usingPureNSQSharp;classProgram{staticvoidMain(){varproducer=newProducer("127.0.0.1:4150");producer.Publish("test-topic-name","Hello!");Console.WriteLine("Enter your message (blank line to quit):");stringline=Console.ReadLine();while(!string.IsNullOrEmpty(line)){producer.Publish("test-topic-name",line);line=Console.ReadLine();}producer.Stop();}}

Simple Consumer

usingSystem;usingSystem.Text;usingPureNSQSharp;classProgram{staticvoidMain(){// Create a new Consumer for each topic/channelvarconsumer=newConsumer("test-topic-name","channel-name");consumer.AddHandler(newMessageHandler());consumer.ConnectToNsqLookupd("127.0.0.1:4161");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();}}publicclassMessageHandler:IHandler{/// <summary>Handles a message.</summary>publicvoidHandleMessage(IMessagemessage){stringmsg=Encoding.UTF8.GetString(message.Body);Console.WriteLine(msg);}/// <summary>/// Called when a message has exceeded the specified <see cref="Config.MaxAttempts"/>./// </summary>/// <param name="message">The failed message.</param>publicvoidLogFailedMessage(IMessagemessage){// Log failed messages}}

Pull Requests

Pull requests and issues are very welcome and appreciated.

License

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

About

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

Resources

Stars

1 star

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages