Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Tips for the Week in .NET

Please comment below...

Package of the week: NATS client

Microservices and IoT both require distributed architectures where a large number of endpoints communicate fast and reliably. NATS is a popular high-performance cloud-based messaging system that is an excellent fit for such scenarios. The .NET client for NATS can publish over 3 million messages per second (and that's in a VM, on a developer laptop).

Here's how you'd send a simple object on the message bus, with a subject “foo”:

using (var cnx = new ConnectionFactory().CreateEncodedConnection())
    cnx.Publish("foo", new Company
        Name = "Apcera",
        Address = "140 New Montgomery St."

Other actors can asynchronously subscribe to the same subject and process objects:

using (var cnx = new ConnectionFactory().CreateEncodedConnection()) {
    using (cnx.SubscribeAsync("foo", (sender, args) => {
        var company = (Company)args.ReceivedObject;
        Console.WriteLine($"Name: {company.Name}, Address: {company.Address}");
    })) {
        System.Console.WriteLine("Waiting for a message...");

You can read more about the NATS .NET client in NATS In Microsoft .NET.




This comment has been minimized.

Copy link

commented Jan 13, 2016 - a library to export data to Excel, comparing to existing libraries it's many times faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.