Define a contract and many implementations (Azure EventGrid, Azure ServiceBus, Azure Storage Queues, Azure Redis) for publish and subscribe
ERNI Academy StarterKit, PoC, or Gidelines. This is an about description of your repository.
This section should list any major frameworks that you built your project using. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
- Publish
- PublishAsync
- Subscribe
- Subscribe
- UnSubscribe
- StarProcessingAsync
- StopProcessingAsync
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
.net 6 Visual Studio or Visual Studio Code
Installation instructions Events Abstraction by running:
- Clone the repo
git clone --recurse-submodules https://github.com/ERNI-Academy/assets-events-abstraction.git
Important Note
All implementations heavly depends on Microsoft Options Pattern for configurations. See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0 So it is expected a proper configuration in order to work take a look at the samples to see how to configure each publisher/subscriber All implementatins also depends on Microsoft logging. See https://docs.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line
- Publish Basic use
class MyEvent : EventBase
{
public string MyCustomProperty { get; set; }
}
var @event = new MyEvent { MyCustomProperty = "hi" };
//you can choose between many impl
IEventPublisher publisher = new ErniAcademy.Events.EventGrid.EventGridPublisher();//args ommited for simplicity
IEventPublisher publisher = new ErniAcademy.Events.Redis.RedisPublisher();//args ommited for simplicity
IEventPublisher publisher = new ErniAcademy.Events.ServiceBus.ServiceBusPublisher();//args ommited for simplicity
IEventPublisher publisher = new ErniAcademy.Events.StorageQueues.StorageQueuePublisher();//args ommited for simplicity
//just publish your event
await publisher.PublishAsync(@event);
- Publish Depency injection (ServiceCollection)
class MyEvent : EventBase
{
public string MyCustomProperty { get; set; }
}
//when configuring your ServiceCollection use the extension methods defined in each library for easy of use.
//This sample is provided with no arguments, take a look on the extensions to see the rest of the arguments, like IConfiguration, ISerializer etc.
services.AddEventsPublisherEventGrid();//args ommited for simplicity
services.AddEventsPublisherRedis();//args ommited for simplicity
services.AddEventsPublisherServiceBus();//args ommited for simplicity
services.AddEventsPublisherStorageQueues();//args ommited for simplicity
//then just inject IEventPublisher directly in your classes
class MyService
{
private readonly IEventPublisher _publisher;
public MyService(IEventPublisher publisher)
{
_publisher = publisher;
}
public async Task SomeMethod()
{
//... some logic
var @event = new MyEvent { MyCustomProperty = "hi" };
//just publish your event
await _publisher.PublishAsync(@event);
}
}
- Subscribe Basic use
class MyEvent : EventBase
{
public string MyCustomProperty { get; set; }
}
//you can choose between many impl
IEventPublisher subscriber = new ErniAcademy.Events.Redis.RedisSubscriber();//args ommited for simplicity
IEventPublisher subscriber = new ErniAcademy.Events.ServiceBus.ServiceBusSubscriber();//args ommited for simplicity
IEventPublisher subscriber = new ErniAcademy.Events.StorageQueues.StorageQueueSubscriber();//args ommited for simplicity
//first subscribe to an @event by passing a handler to subscribe method
subscriber.ProcessEventAsync += MyProcessor;
private Task MyProcessor(MyEvent @event)
{
//Process @event
}
//start processing events
await subscriber.StarProcessingAsync();
//and when you are done
await subscriber.StopProcessingAsync();
- Subscribe Depency injection (ServiceCollection)
class MyEvent : EventBase
{
public string MyCustomProperty { get; set; }
}
//when configuring your ServiceCollection use the extension methods defined in each library for easy of use.
//This sample is provided with no arguments, take a look on the extensions to see the rest of the arguments, like IConfiguration, ISerializer etc.
services.AddEventsSubscriberRedis<MyEvent>();//args ommited for simplicity
services.AddEventsSubscriberServiceBus<MyEvent>();//args ommited for simplicity
services.AddEventsSubscriberStorageQueues<MyEvent>();//args ommited for simplicity
//then just inject IEventPublisher directly in your classes
class MyService
{
private readonly IEventSubscriber<DummyEvent> _subscriber;
public MyService(IEventSubscriber<DummyEvent> subscriber)
{
_subscriber = subscriber;
}
public async Task SomeMethod()
{
//first subscribe to an @event by passing a handler to subscribe method
_subscriber.ProcessEventAsync += MyProcessor;
//start processing events
await _subscriber.StarProcessingAsync();
//and when you are done
await _subscriber.StopProcessingAsync();
}
private Task MyProcessor(MyEvent @event)
{
//Process @event
}
}
Please see our Contribution Guide to learn how to contribute.
(LICENSE) Β© 2022 ERNI - Swiss Software Engineering
Please see our Code of Conduct
π§ [email protected]
Thanks goes to these wonderful people (emoji key):
omaramalfi π» π π π¨ π€ π§ |
This project follows the all-contributors specification. Contributions of any kind welcome!