devr24 / Cloud.Core.Messaging.AzureStorageQueue

Azure Storage Queue implementation of the IMessenger interfaces.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloud.Core.Messaging.AzureStorageQueue

Build status Code Coverage Cloud.Core.Messaging.AzureStorageQueue package in Cloud.Core feed in Azure Artifacts

Azure storage queue specific implementation of queue storage interface. Uses the IReactiveMessenger or IMessenger interface from Cloud.Core.

Read full Api documentation

Usage

Initialisation and Authentication Usage

There are three ways you can instantiate the Queue Storage Client. Each way dictates the security mechanism the client uses to connect. The three mechanisms are:

  1. Connection String
  2. Service Principle
  3. Managed Service Identity

Below are examples of instantiating each type.

1. Connection String

Create an instance of the Queue Storage client using a connection string as follows:

var connConfig = new ConnectionConfig
    {
        ConnectionString = "<connectionstring>",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }
    };

// Queue storage client.
var queuestorage = new QueueStorage(connConfig);		

Note: Instance name not required to be specified anywhere in configuration here as it is taken from the connection string itself.

2. Service Principle

Create an instance of the Queue Storage client with Service Principle authentication as follows:

var spConfig = new ServicePrincipleConfig
    {
        AppId = "<appid>",
        AppSecret = "<appsecret>",
        TenantId = "<tenantid>",
        InstanceName = "<queueinstancename>",
        SubscriptionId = "<subscriptionId>",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }
    };

// Queue storage client.
var queuestorage = new QueueStorage(spConfig);	

3. Management Service Idenity (MSI)

This authentication also works for Managed User Identity. Create an instance of the Queue Storage client with MSI authentication as follows:

var msiConfig = new MsiConfig
    {
        TenantId = "<tenantid>",
        InstanceName = "<queueinstancename>",
        SubscriptionId = "<subscriptionId>",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }
    };

// Queue storage client.
var queuestorage = new QueueStorage(msiConfig);	

All that's required is the instance name, tenantId and subscriptionId to connect to. Authentication runs under the context the application is running.

Dependency Injection

Inserting into dependency container:

// Add multiple instances of state storage.
services.AddStorageQueueSingletonNamed<IReactiveMessenger>("QM1", "queueStorageInstanceName", "tenantId", "subscriptionId",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }); 

// add to factory using a key
services.AddStorageQueueSingletonNamed<IReactiveMessenger>("QM2", "queueStorageInstanceName2", "tenantId", "subscriptionId",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }); 

// add to factory using a key
serviceCollection.AddQueueStorageSingleton<IMessenger>("tableStorageInstance3", "tenantId", "subscriptionId",
        ReceiverSetup = new ReceiverSetup { ... }, 
        SenderSetup = new SenderSetup { ... }); 

// Sample consuming class.
services.AddTransient<MyClass>();

Using the dependencies:

public class MyClass {

    private readonly IReactiveMessenger _messageInstance1;
    provate readonly IReactiveMessenger _messageInstance2;
    private readonly IMessenger _messageInstance3;

    public MyClass(NamedInstanceFactory<IReactiveMessenger> messengerFactor, IMessenger singleMessengerInstance) 
    {	
	_messageInstance1 = messengerFactor["QM1"];
	_messageInstance2 = messengerFactor["QM2"];
	_messageInstance3 = singleMessengerInstance;
    }	
    ...
}

Test Coverage

A threshold will be added to this package to ensure the test coverage is above 80% for branches, functions and lines. If it's not above the required threshold (threshold that will be implemented on ALL of the core repositories to gurantee a satisfactory level of testing), then the build will fail.

Compatibility

This package has has been written in .net Standard and can be therefore be referenced from a .net Core or .net Framework application. The advantage of utilising from a .net Core application, is that it can be deployed and run on a number of host operating systems, such as Windows, Linux or OSX. Unlike referencing from the a .net Framework application, which can only run on Windows (or Linux using Mono).

Setup

This package is built using .net Standard 2.1 and requires the .net Core 3.1 SDK, it can be downloaded here: https://www.microsoft.com/net/download/dotnet-core/

IDE of Visual Studio or Visual Studio Code, can be downloaded here: https://visualstudio.microsoft.com/downloads/

How to access this package

All of the Cloud.Core.* packages are published to a public NuGet feed. To consume this on your local development machine, please add the following feed to your feed sources in Visual Studio: https://dev.azure.com/cloudcoreproject/CloudCore/_packaging?_a=feed&feed=Cloud.Core

For help setting up, follow this article: https://docs.microsoft.com/en-us/vsts/package/nuget/consume?view=vsts

About

Azure Storage Queue implementation of the IMessenger interfaces.

License:MIT License


Languages

Language:C# 100.0%