NTDLS.MemoryQueue 2.2.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package NTDLS.MemoryQueue --version 2.2.8
                    
NuGet\Install-Package NTDLS.MemoryQueue -Version 2.2.8
                    
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="NTDLS.MemoryQueue" Version="2.2.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NTDLS.MemoryQueue" Version="2.2.8" />
                    
Directory.Packages.props
<PackageReference Include="NTDLS.MemoryQueue" />
                    
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 NTDLS.MemoryQueue --version 2.2.8
                    
#r "nuget: NTDLS.MemoryQueue, 2.2.8"
                    
#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 NTDLS.MemoryQueue@2.2.8
                    
#: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=NTDLS.MemoryQueue&version=2.2.8
                    
Install as a Cake Addin
#tool nuget:?package=NTDLS.MemoryQueue&version=2.2.8
                    
Install as a Cake Tool

NTDLS.MemoryQueue

📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.MemoryQueue

In memory non-persistent message queue intended for inter-process-communication, queuing, load-balancing and buffering over TCP/IP.

Running the server:

Running the server can literally be done with two lines of code and can be run in the same process as the client. The server does not have to be dedicated either, it can be one of the process that is involved in inner-process-communication.

internal class Program
{
    static var _server = new MqServer(); //Literal line #1.

    static void Main()
    {
        _server.Start(45784); //Literal line #2.

        Console.WriteLine("Press [enter] to shutdown.");
        Console.ReadLine();

        server.Stop();
    }
}

Enqueuing a message.

Enqueuing a one-way message that is broadcast to all connected peers that have subscribed to the queue.

internal class Program
{
    internal class MyMessage : IMqMessage
    {
        public string Text { get; set; }

        public MyMessage(string text)
        {
            Text = text;
        }
    }

    static void Main()
    {
        //Start a client and connect to the server.
        var client = new MqClient();

        //Enqueue a one-way message to be distributed to all subscribers.
        client.Enqueue("MyFirstQueue", new MyMessage("This is a message"));

        Console.WriteLine("Press [enter] to shutdown.");
        Console.ReadLine();

        client.Disconnect();
    }
}

Receiving a notification message

Receiving a notification is easy. If you are subscribed to the queue, you will receive the message. Further messages will be held until the event method returns.

internal class Program
{
    internal class MyMessage(string text): IMqMessage
    {
        public string Text { get; set; } = text;
    }

    static void Main()
    {
        var client = new MqClient();

        //Connect to the queue server.
        client.Connect("localhost", 45784);

        //Wire up the OnMessageReceived event.
        client.OnMessageReceived += Client_OnMessageReceived;

        //Create a queue, its ok its it already exists.
        client.CreateQueue("MyFirstQueue");

        //Subscribe to the queue.
        client.Subscribe("MyFirstQueue");

        Console.WriteLine("Press [enter] to shutdown.");
        Console.ReadLine();

        client.Disconnect();
    }

    private static bool Client_OnReceived(MqClient client, IMqMessage message)
    {
        //We received a message. Use pattern matching to determine what message was received.
        if (message is MyMessage myMessage)
        {
            Console.WriteLine($"Client received message from server: {myMessage.Text}");
        }

        return true; //Return true to tell the server we received and processed the message.
    }
}

License

MIT

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
2.2.18 174 11/14/2025
2.2.17 177 5/2/2025
2.2.16 154 1/8/2025
2.2.14 180 1/4/2025
2.2.13 179 12/31/2024
2.2.12 145 12/31/2024
2.2.11 161 12/27/2024
2.2.10 158 12/26/2024
2.2.9 160 12/26/2024
2.2.8 154 12/26/2024
2.2.7 177 12/26/2024
2.2.5 152 12/26/2024
2.2.4 156 12/26/2024
2.2.3 154 12/26/2024
2.2.2 150 12/26/2024
2.2.1 170 12/26/2024
2.2.0 162 12/26/2024
2.1.0 150 12/26/2024
2.0.7 151 12/23/2024
2.0.6 171 12/22/2024
2.0.5 160 12/22/2024
2.0.4 149 12/22/2024
2.0.2 153 12/22/2024
2.0.1 148 12/22/2024
2.0.0 153 12/21/2024
1.1.5 159 12/3/2024
1.1.4 237 1/22/2024
1.1.3 184 1/22/2024
1.1.2 281 11/15/2023
1.1.1 186 11/12/2023
1.1.0 191 11/9/2023
1.0.0 204 11/8/2023

Nullability meta fix.