Chirp 1.0.0
See the version list below for details.
dotnet add package Chirp --version 1.0.0
NuGet\Install-Package Chirp -Version 1.0.0
<PackageReference Include="Chirp" Version="1.0.0" />
<PackageVersion Include="Chirp" Version="1.0.0" />
<PackageReference Include="Chirp" />
paket add Chirp --version 1.0.0
#r "nuget: Chirp, 1.0.0"
#:package Chirp@1.0.0
#addin nuget:?package=Chirp&version=1.0.0
#tool nuget:?package=Chirp&version=1.0.0
Chirp - Flexible Messaging Library
Chirp is a flexible, provider-agnostic messaging library that simplifies publishing and consuming messages across various message brokers, including RabbitMQ, Kafka, Redis, Azure Service Bus, Amazon SQS, NATS, and Google PubSub.
Features
- Provider-agnostic API for messaging operations
- Unified interface for multiple message brokers
- Simple integration with dependency injection
- Support for multiple message brokers:
- RabbitMQ (fully implemented)
- Kafka (planned)
- Redis (planned)
- Azure Service Bus (planned)
- Amazon SQS (planned)
- NATS (planned)
- Google PubSub (planned)
- Message retries with configurable retry counts
- Dead letter exchange/queue support for failed messages
- Clean subscription management with in-memory event tracking
Installation
dotnet add package Chirp
Getting Started
Configuration
Add the necessary configuration to your appsettings.json:
{
"RMQ": {
"Host": "localhost",
"Port": 5672,
"Username": "guest",
"Password": "guest",
"ExchangeName": "chirp_exchange",
"ExchangeNameDLX": "chirp_dlx_exchange"
}
}
Setting Up Dependencies
Register the required dependencies in your Program.cs
or Startup.cs
:
using Chirp.Application.Interfaces;
using Chirp.Domain.Common;
using Chirp.Infrastructure.EventBus;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
// Add Chirp services with RabbitMQ implementation
services.AddChirp(options =>
{
options.EventBusType = EventBusType.RabbitMQ;
options.QueueName = "my_service_queue";
options.RetryCount = 3;
});
Creating Events
Create event classes that inherit from IntegrationEvent
:
using Chirp.Domain.Common;
public record OrderCreatedEvent(int OrderId, string CustomerName, decimal Total) : IntegrationEvent;
Creating Event Handlers
Create handlers that implement IIntegrationEventHandler<T>
:
using Chirp.Application.Interfaces;
public class OrderCreatedEventHandler : IIntegrationEventHandler<OrderCreatedEvent>
{
public async Task Handle(OrderCreatedEvent @event)
{
// Process the event
Console.WriteLine($"Order {event.OrderId} created for {event.CustomerName} with total {event.Total}");
await Task.CompletedTask;
}
}
Publishing Events
Inject IEventBus
and publish events:
public class OrderService
{
private readonly IEventBus _eventBus;
public OrderService(IEventBus eventBus)
{
_eventBus = eventBus;
}
public void CreateOrder(int orderId, string customerName, decimal total)
{
// Create and publish the event
var orderCreatedEvent = new OrderCreatedEvent(orderId, customerName, total);
_eventBus.Publish(orderCreatedEvent);
}
}
Subscribing to Events
Subscribe to events in your application startup:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
// Subscribe to events
eventBus.Subscribe<OrderCreatedEvent, OrderCreatedEventHandler>();
}
}
Advanced Usage
Using the Event Bus Factory
You can also use the EventBusFactory
to create an instance of the event bus:
IEventBus eventBus = EventBusFactory.Create(
EventBusType.RabbitMQ,
serviceProvider,
configuration,
"my_service_queue",
retryCount: 5);
Working with Multiple Event Bus Implementations
If your application needs to work with multiple message brokers:
// Configure RabbitMQ
services.AddChirp(options =>
{
options.EventBusType = EventBusType.RabbitMQ;
options.QueueName = "rabbitmq_queue";
});
// Add Redis (when implemented)
services.AddChirpRedis(options =>
{
options.ChannelName = "redis_channel";
});
Supported Message Brokers
Provider | Status | Configuration Section |
---|---|---|
RabbitMQ | ? Implemented | RMQ |
Kafka | ?? Planned | Kafka |
Redis | ?? Planned | Redis |
Azure Service Bus | ?? Planned | AzureServiceBus |
Amazon SQS | ?? Planned | AWS:SQS |
NATS | ?? Planned | NATS |
Google PubSub | ?? Planned | GooglePubSub |
Contributing
Contributions are welcome! Feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Created by Andrew Eberle
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Polly (>= 8.5.2)
- RabbitMQ.Client (>= 6.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.