Globals.NET.RabbitMQ 1.0.7

dotnet add package Globals.NET.RabbitMQ --version 1.0.7
NuGet\Install-Package Globals.NET.RabbitMQ -Version 1.0.7
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="Globals.NET.RabbitMQ" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Globals.NET.RabbitMQ --version 1.0.7
#r "nuget: Globals.NET.RabbitMQ, 1.0.7"
#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.
// Install Globals.NET.RabbitMQ as a Cake Addin
#addin nuget:?package=Globals.NET.RabbitMQ&version=1.0.7

// Install Globals.NET.RabbitMQ as a Cake Tool
#tool nuget:?package=Globals.NET.RabbitMQ&version=1.0.7

The Globals Design Pattern

The Globals Communication Pattern describes a way to make communication between systems death simple, hiding away all technical details.

This package contains a .NET & RabbitMQ implementation of this pattern.

For the examples, click here

Working (C#): On the sending side, you declare a Global of a certain type and name.

using (Global<string> HelloWorld = new Global<string>("HelloWorld"))    // a declaration...
{
    HelloWorld.Value = "Hello, World!";     // assign a value, and we are done!
    ...
}

On the receiving side, you declare the same Global (same name, same type) and add a DataChanged handler.

// a declaration plus event handler
using (Global<string> HelloWorld = new Global<string>("HelloWorld", handler: HelloWorld_DataChanged))
{  
    ...
}

private static void HelloWorld_DataChanged(object sender, GlobalEventData<string> e)
{
    Console.WriteLine(e.Data);   // Output: Hello, world!
}

On the moment a value is assigned by the Sending side, a DataChanged event is raised on the receiving side.

With this mechanism, you can send a stream of data as well:

using (Global<string> HelloWorld = new Global<string>("HelloWorld"))    // a declaration...
{
    for (int i = 0; i < 100; i++)
    {
        HelloWorld.Value = $"Hello, World! This is greeting number {i}!"; 
    }
    ...
}

On the receiving side, 100 DataChanged events are raised, in the same order as it was sent.

Below the complete example to send and receive a single greeting over the network:

The Sender:

using System;
using Globals.NET.RabbitMQ;  // the package

namespace Sender
{
    class Program
    {
        static void Main()
        {
            using (Global<string> HelloWorld = new Global<string>("HelloWorld"))    // a declaration...
            {
                HelloWorld.Value = "Hello, World!";     // assign a value, and we are done!

                Console.ReadLine();
                Console.WriteLine("Stopping...");
            };
        }
    }
}

The Receiver:

using System;
using Globals.NET.RabbitMQ;  // the package

namespace Receiver
{
    class Program
    {
        static void Main()
        {
            using Global<string> HelloWorld = new Global<string>("HelloWorld", handler: HelloWorld_DataChanged);  // a declaration plus event handler

            Console.ReadLine();
            Console.WriteLine("Stopping...");
        }
        private static void HelloWorld_DataChanged(object sender, GlobalEventData<string> e)
        {
            Console.WriteLine(e.Data);   // Output: Hello, world!
        }
    }
}

The Rule:

Globals with the same name have the same value.

Getting Started

Prerequisites

  • This package uses RabbitMQ as the communication layer, this should be installed first.
  • This package is created to be used within the .NET Framework (.NET Standard 2.0), a version of Visual Studio can be downloaded here.

Installing

Once the Prerequisites section is done, create you first Hello World application following the steps below. In this description it is assumed you work with some version of Visual Studio. We will start with:

The Sender:

1. Start Visual Studio and create an empty Console Application:
  1. Create a new project
  2. Select as project type: Console App, C#, either .NET Core or .NET Framework.
  3. Click Next
  4. Give your project a nice name, like "HelloWorld_Sender"
  5. Click on 'Create'

Visual Studio opens the editor with a small program:

using System;

namespace HelloWorld_Sender
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
2. Install the Globals.NET.RabbitMQ NuGet package:
  1. Select Tools - NuGet Package Manager - Manage NuGet Packages for Solution...
  2. Click on the Browse tab
  3. In the Search bar, type Globals.NET.RabbitMQ.
  4. Select the Globals.NET.RabbitMQ package in the window below the search bar.
  5. Check the HellowWorld_Sender checkbox and click on install.

After installation is complete:

  1. Close the window
3. Copy & Paste the Sender Code in program.cs:
using System;
using Globals.NET.RabbitMQ;  // the package

namespace Sender
{
    class Program
    {
        static void Main()
        {
            using (var HelloWorld = new Global<string>("HelloWorld"))    // a declaration...
            {
                HelloWorld.Value = "Hello, World!";     // assign a value, and we are done!

                Console.ReadLine();
                Console.WriteLine("Stopping...");
            };
        }
    }
}
4. Add an App.Config file to your project and enter 5 configuration parameters:
  1. Right-click on the project HelloWorld_Sender, and click Add - New Item.
  2. In the search bar, type 'config'.
  3. Select the ' Application Configuration File' and click 'Add' .

Your App.Config file is added and opened.

  1. Add your 5 RabbitMQ parameters:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="HostName" value="localhost"/>
    <add key="Port" value="5672"/>
    <add key="UserName" value="guest"/>
    <add key="Password" value="guest"/>
    <add key="VirtualHost" value="/"/>
  </appSettings>
</configuration>

To get your parameters right, please see the RabbitMQ documentation

The Receiver:

Follow the same steps as with creating the sender, but now give the project the name HelloWorld_Receiver, and replace your program.cs code with:

using System;
using Globals.NET.RabbitMQ;  // the package

namespace Receiver
{
    class Program
    {
        static void Main()
        {
            using var HelloWorld = new Global<string>("HelloWorld", handler: HelloWorld_DataChanged);  // a declaration plus event handler

            Console.ReadLine();
            Console.WriteLine("Stopping...");
        }
        private static void HelloWorld_DataChanged(object sender, GlobalEventData<string> e)
        {
            Console.WriteLine(e.Data);   // The data is received here!
        }
    }
}

Built With / Tools Used

Resources

Author

License

This project is licensed under the MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Additional computed target framework(s)
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.7 86 2/4/2024
1.0.6 186 12/10/2023
1.0.5 596 6/15/2020
1.0.4 441 5/25/2020
1.0.3 491 5/25/2020
1.0.2 463 5/25/2020
1.0.1 462 5/25/2020
1.0.0 460 5/25/2020

An implementation of the Globals Design Pattern