Skip to content

ERNI-Academy/assets-cloud-servicebus-abstraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

About

Service Bus Topic/Subscriptions Abstraction is a small dll ( on the next iteration, it will be a nuget package) that provides a robust and reusable implementations.

the main focus of this dll is add the publish and listener features to your owns projects.

All Contributors

Built With

Features

  • ServiceBusClient abstraction
  • Message abstraction
  • Listener client
  • Publisher client

Getting Started

At this point, we have to use this project like dll or directly on our production projects.

On next releases, we transform the solution into nuget.

Prerequisites

Dependencies

  • Newtonsoft nuget
  • Azure.Messaging.ServiceBus nuget
  • .NETStandard 2.0
  • System.Text.Json

Installation

At this point, it is possible to use that asset:

  • Cloning the repo and use it directly on you solution. On this way, you will have access too entire code.
git clone https://github.com/ERNI-Academy/assets-cloud-servicebus-abstraction.git
  • Using the dll located on Release folder

Notes

  • At this point only can be used with ServiceBus. On next iteration, it'll be implemented a development mode to be used on localhost environments.

Object definitions

ServiceBusClient

    public interface ISBServiceClient
    {
        IListener GetListener(string topicName = "");
        IPublisher GetPublisher(string topicName = "");
    }

ISBClientConfig client

    public interface ISBConfig
    {
        public string ConnectionString { get; set; }
        public string Topic { get; set; }
        public string Subscription { get; set; }
    }

Listener client

    public interface IListener:IClient
    {
        void Run(Action<IMessage> callback);
    }

Publisher client

    public interface IPublisher:IClient
    {
        void SendAsync(dynamic message);
    }

IMessage

    public interface IMessage : IAbstractMessage
    {
        dynamic Value { get; }
    }

IAbstractMessage

    public interface IAbstractMessage
    {
        Guid Id { get; }
    }

Samples

Create ServiceBusClient

The ServiceBusClient is the services that will create the proper clients( listener or publisher).This service use like configuration a own object SBConfig that implement ISBConfig, so, if you want to change the end implementation of that object you should implement a new one and resolve it on IoC .

 ISBServiceClient service = new ServiceBusClient(new SBConfig()
            {
                ConnectionString = "Endpoint=sb://sbasset.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=+lS3xJGQRsMeucKYHt2SG08VhRGCLZA++CqJm7lhlrQ=",
                Topic = "assetsample",
                Subscription = "assetsubs"
            });
  • To find the correct connectionstring you should go to azure portal -> ServiceBus account -> Shared access policies and there , choose the primary key

Create Listener Client

The listener client is an artifact that bring you the capability to be connected on streaming to the concrete subscription.Once you add a callback to this artifact, your software received all messages sent it to the Topic related with the subscription configured.

    IListener listener = service.GetListener("assetsample");
    listener.Run((message) => { Console.WriteLine(message.ToString()); });

In this sample we have created a lambda function, but you can use more traditional mechanism.

Take aware about you will receive an IMessage object

Create Publisher client

The Publisher is an artefact that bring you the capability to send messages to a concrete Topic.

The object are abtracted into IMessage internal model.

    IPublisher publisher = service.GetPublisher("assetsample");
    for (int i = 0; i < 20; i++)
    {
        publisher.SendAsync(new { prop1 = i.ToString(), prop2 = "2" }); 
        System.Threading.Thread.Sleep(100);
    }

Contributing

Please see our Contribution Guide to learn how to contribute.

License

MIT

(LICENSE) Β© 2022 ERNI - Swiss Software Engineering

Code of conduct

Please see our Code of Conduct

Stats

https://repobeats.axiom.co/api/embed/40ef16dfb701ec4dad65007c5888910f45265d44.svg

Follow us

Twitter Follow Twitch Status YouTube Channel Views Linkedin

Contact

πŸ“§ esp-services@betterask.erni

Manu Delgado - @mdelgadodiaz83 - mdelgadodiaz83@gmail.com

Contributors ✨

Thanks goes to these wonderful people (emoji key):


mdelgadodiaz83-erni

πŸ’» πŸ–‹ πŸ“– 🎨 πŸ€” 🚧 ⚠️ πŸ’‘ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

About

With this package we standardize the usage and implementation of Azure Service bus in all your code.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages