NeoBus is a powerful library that enables you to send commands, queries, and events using the CQRS pattern in .NET. It simplifies the implementation of distributed systems and event-driven architectures by seamlessly integrating with Kafka. If you find NeoBus helpful, please consider giving it a star ⭐ to show your support.
You can easily install NeoBus via NuGet Package Manager:
> Install-Package NeoBus
To configure NeoBus, add the following settings to your appsettings.json
file and specify your Kafka server address:
"NeoBus": {
"Kafka": {
"Servers": ["localhost:9092"]
}
}
Incorporate NeoBus into your project by registering it in the Startup.cs
file within the ConfigureServices
method:
services.AddNeoBus(Assembly.GetExecutingAssembly());
For distributed events using Kafka, register the necessary services as follows:
services.AddHostedService<KafkaEventSubscriberService<ProductAddedEventOnKafka, ProductAddedEventOnKafkaHandler>>();
services.AddSingleton<ProductAddedEventOnKafkaHandler>();
If you are using a version lower than 1.2.0, use the following code to register and manually register commands and queries:
services.AddNeoBus();
To register commands and queries, follow these steps:
services.AddScoped<IRequestHandler<ProductAddCommand, CommandResult>, ProductAddCommandHandler>();
services.AddScoped<IRequestHandler<GetProductQuery, CommandResult>, GetProductQueryHandler>();
services.AddScoped<INotificationHandler<ProductAddedEvent>, ProductAddedEventHandler>();
Explore a sample project that demonstrates how to use NeoBus:
To run Kafka locally, follow these instructions:
- Install Docker on your local machine.
- Download the
docker-compose-kafka.yml
file from within the project solution. - Open your Terminal as an administrator.
- Navigate to the directory containing the
docker-compose-kafka.yml
file. - Run the following command:
docker-compose -f docker-compose-kafka.yml up
Now Kafka is up and running in a Docker container.
For more information about NeoBus and its applications, consider reading the following articles:
- EventBus Application and Introduction of NeoBus Package
- کاربرد EventBus و معرفی پکیج NeoBus (Persian)
Feel free to explore these resources to enhance your understanding of NeoBus and its capabilities.