Toosame.EventBus
1.0.6
See the version list below for details.
dotnet add package Toosame.EventBus --version 1.0.6
NuGet\Install-Package Toosame.EventBus -Version 1.0.6
<PackageReference Include="Toosame.EventBus" Version="1.0.6" />
paket add Toosame.EventBus --version 1.0.6
#r "nuget: Toosame.EventBus, 1.0.6"
// Install Toosame.EventBus as a Cake Addin #addin nuget:?package=Toosame.EventBus&version=1.0.6 // Install Toosame.EventBus as a Cake Tool #tool nuget:?package=Toosame.EventBus&version=1.0.6
Toosame.RabbitMQ
An Event Bus Based on RabbitMQ, whose core code is from eShopOnContainers, I just pulled it out and made some extensions, fixes and improvements.
I currently only use it for microservices. If your project has only one ASP. NET Core project, then it may not be suitable for you.
Install from Nuget.org
PM> Install-Package Toosame.EventBus.RabbitMQ -Version 1.1.1
Using (Publish Event)
- Add Event
- Add Event Handler
- Publish Event in Controller
1. Add Event
Create YourEvent.cs
public class YourEvent : IntegrationEvent
{
public string Name { get; set; }
public int Age { get; set; }
}
2. Add Event Handler
Create YourEventHandler.cs
public class YourEventHandler : IIntegrationEventHandler<YourEvent>
{
private readonly IConfiguration _configuration;
public YourEventHandler(IConfiguration configuration){
//I'm just telling you that you can also use Dependency Injection Services.
_configuration = configuration;
}
public Task Handle(YourEvent @event)
{
//you can get @event.Name
//you can get @event.Age
//Do something...
return Task.CompletedTask;
}
}
3. Publish Event in Controller
public class HomeController : Controller
{
private readonly IEventBus _eventBus;
public YourEventHandler(IEventBus eventBus){
_eventBus = eventBus;
}
[HttpGet]
public IAcionResult Index(){
_eventBus.Publish(new YourEvent(){
Name: "my name",
Age: 22
})
}
}
Setup
You can subscribe to the event you just created here.
- Configure appsettings.json
- Setup on
Startup.cs
1. Configure appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"RabbitMQ": {
"EventBusConnection": "<yourRabbitMqHost>[:port(default 5672)]",
"EventBusUserName": "<rabbitMqUserName>",
"EventBusPassword": "<rabbitMqPassword>",
"EventBusRetryCount": 5,
"EventBusBrokeName": "<rabbitMqExchangeName>",
"SubscriptionClientName": "<queueName>" //It's better to have different microservices with different names
}
}
2.Setup on Startup.cs
Standard:
public void ConfigureServices(IServiceCollection services)
{
services.AddEventBus(Configuration.GetSection("RabbitMQ").Get<RabbitMQOption>(),
eventHandlers =>
{
eventHandlers.AddEventHandler<YourEventHandler1>();
eventHandlers.AddEventHandler<YourEventHandler2>();
});
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseEventBus(eventBus =>
{
eventBus.Subscribe<YourEvent1, YourEventHandler1>();
eventBus.Subscribe<YourEvent2, YourEventHandler2>();
});
app.UseMvc();
}
Using Autofac
:
Please install
Autofac.Extensions.DependencyInjection
package.As below:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddControllersAsServices();
return services.AddEventBusAsAutofacService(Configuration.GetSection("RabbitMQ").Get<RabbitMQOption>(),
eventHandlers =>
{
eventHandlers.AddEventHandler<YourEventHandler1>();
eventHandlers.AddEventHandler<YourEventHandler2>();
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseEventBus(eventBus =>
{
eventBus.Subscribe<YourEvent1, YourEventHandler1>();
eventBus.Subscribe<YourEvent2, YourEventHandler2>();
});
app.UseMvc();
}
Product | Versions 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. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 12.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Toosame.EventBus:
Package | Downloads |
---|---|
Toosame.EventBus.RabbitMQ
EventBus Implementation of RabbitMQ |
GitHub repositories
This package is not used by any popular GitHub repositories.