Simple PubSub Project to push and receive events in a distributed cloud enviroment
clone or via Nuget: ai.we-do.pubsub
The project is based on two concepts:
... you can push messages to and that are also responsible for dispatching incomming messages
The EventHub
class should be derived for your own usage so that you can easily create multiple hubs:
public class GlobalEventHub : EventHub
{
public GlobalEventHub(IEventConnection connection) : base(connection)
{
}
protected override Func<Task> Dispatch(EventItem eventItem)
{
// Dispatch the event right here
return () => Task.CompletedTask;
}
if you need dedicated channels in your connection pass the channel name as string in the constructor and call base(connection, channelName)
... that provide pub sub functionalities for different infrastructure components. Already included is a Redis and a Azure Storage Bus Connection
The IEventConnection
interface contains two methods: Subscribe
and PublishNewMessageAsync
- Add the following in your Startup.cs:
services.AddSingleton<IEventConnection, RedisEventConnection>();
services.AddSingleton<GlobalEventHub>();
be aware that the GlobalEventHub gets called when it is injected by another component and the subscription is not active until it is first used. So maybe you want to create the Eventhub manually or inject it in public void Configure
in your Startup.cs
- add connection strings to your appSettings.json:
Redis example:
"ConnectionStrings": {
"EventHubRedisCache": "yourserver.domain.tld:6380,password=yourfancypassword,ssl=True,abortConnect=False"
},
Azure Storage Bus Example
"ConnectionStrings": {
"EventHubAzureStorageBus": "Endpoint=sb://yourservicebusname.servicebus.windows.net/;SharedAccessKeyName=YourSharedAccessKey;SharedAccessKey=YourSharedAccessKey"
},