A set of source generators for MassTransit message handling, supporting both Azure Service Bus and RabbitMQ.
Zooper.Cheetah.Generators.AzureServiceBus- Source generator for Azure Service Bus message handlingZooper.Cheetah.Generators.RabbitMq- Source generator for RabbitMQ message handling
dotnet add package Zooper.Cheetah.Generators.AzureServiceBusdotnet add package Zooper.Cheetah.Generators.RabbitMqCreate a class to represent your message:
using Zooper.Cheetah.Attributes;
[Channel("orders")] // For Azure Service Bus, this defines the topic name
[ExchangeName("orders")] // For RabbitMQ, this defines the exchange name
public class OrderCreated
{
public Guid OrderId { get; set; }
public string CustomerName { get; set; }
public decimal TotalAmount { get; set; }
}using MassTransit;
using Zooper.Cheetah.Attributes;
[Consumer("orders", "order-created-handler")] // Topic name and subscription name
public class OrderCreatedHandler : IConsumer<OrderCreated>
{
public async Task Consume(ConsumeContext<OrderCreated> context)
{
// Your message handling logic here
Console.WriteLine($"Order {context.Message.OrderId} created for {context.Message.CustomerName}");
}
}using MassTransit;
using Zooper.Cheetah.Attributes;
[Consumer("orders", "order-created-queue")] // Exchange name and queue name
public class OrderCreatedHandler : IConsumer<OrderCreated>
{
public async Task Consume(ConsumeContext<OrderCreated> context)
{
// Your message handling logic here
Console.WriteLine($"Order {context.Message.OrderId} created for {context.Message.CustomerName}");
}
}services.AddMassTransit(x =>
{
x.UsingAzureServiceBus((context, cfg) =>
{
cfg.Host("your-connection-string");
// The source generator will automatically configure your message handlers
cfg.ConfigureEndpoints(context);
});
});services.AddMassTransit(x =>
{
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host("localhost", "/", h =>
{
h.Username("guest");
h.Password("guest");
});
// The source generator will automatically configure your message handlers
cfg.ConfigureEndpoints(context);
});
});- Automatic message handler registration
- Type-safe message handling
- Support for both Azure Service Bus and RabbitMQ
- Source-generated code for better performance
- No runtime reflection
- .NET 8.0 or later
- MassTransit 8.4.0 or later
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.