MyServiceBus (a working title) is a lightweight asynchronous messaging library inspired by MassTransit. It is designed to be minimal yet compatible with the MassTransit message envelope format and protocol, enabling services to send, publish, and consume messages across .NET and Java implementations or directly with MassTransit clients.
See samples below.
- Provide a community-driven, open-source alternative to MassTransit and MediatR as they move toward commercial licensing.
- Offer a familiar API for developers coming from MassTransit.
- Ensure wire-level and API compatibility with MassTransit so any client can communicate with MassTransit services.
- Maintain feature parity between the C# and Java clients with consistent behavior across languages. See the design guidelines for architectural and feature parity.
- Fire-and-forget message sending
- Publish/subscribe pattern
- Request/response pattern (
RequestClient
and scoped client factory) - RabbitMQ transport
- In-memory mediator
- Compatibility with MassTransit message envelopes
- Raw JSON messages
- Fault and error handling semantics aligned with MassTransit
- Pipeline behaviors
- OpenTelemetry support
- Annotated for use with the CheckedExceptions analyzer
- Java client and server prototypes
- .NET SDK
- Java (for the Java modules): JDK 17 (Gradle wrapper included)
- .NET
dotnet restore dotnet build
- Java build/run instructions are documented in src/Java/README.md.
- .NET
dotnet test
- Java
(cd src/Java && ./gradlew test)
Minimal steps to configure MyServiceBus and publish a message. For a broader tour of the library, see the feature walkthrough divided into basics and advanced sections.
Register the bus with the ASP.NET host builder:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddServiceBus(x =>
{
x.AddConsumer<SubmitOrderConsumer>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.ConfigureEndpoints(context);
});
});
var app = builder.Build();
await app.StartAsync();
var bus = app.Services.GetRequiredService<IMessageBus>();
Define the messages and consumer:
public record SubmitOrder(Guid OrderId);
public record OrderSubmitted(Guid OrderId);
class SubmitOrderConsumer : IConsumer<SubmitOrder>
{
public Task Consume(ConsumeContext<SubmitOrder> context) =>
context.Publish(new OrderSubmitted(context.Message.OrderId));
}
Publish the SubmitOrder
message 🚀:
await bus.Publish(new SubmitOrder(Guid.NewGuid()),
ctx => ctx.Headers["trace-id"] = Guid.NewGuid());
Register the bus:
ServiceCollection services = new ServiceCollection();
RabbitMqBusFactory.configure(services, x -> {
x.addConsumer(SubmitOrderConsumer.class);
}, (context, cfg) -> {
cfg.configureEndpoints(context);
});
ServiceProvider provider = services.buildServiceProvider();
ServiceBus bus = provider.getService(ServiceBus.class);
bus.start().join();
Define the messages and consumer:
record SubmitOrder(UUID orderId) { }
record OrderSubmitted(UUID orderId) { }
class SubmitOrderConsumer implements Consumer<SubmitOrder> {
@Override
public CompletableFuture<Void> consume(ConsumeContext<SubmitOrder> context) {
return context.publish(new OrderSubmitted(context.getMessage().orderId()));
}
}
Publish the SubmitOrder
message:
bus.publish(new SubmitOrder(UUID.randomUUID()), ctx -> ctx.getHeaders().put("trace-id", UUID.randomUUID())).join();
src/
– C# and Java source codetest/
– Test projectsdocs/
– Documentation for using MyServiceBus, including emoji usage guidelines. Development documents live indocs/development/
.docker-compose.yml
– Docker configuration for local infrastructure
- See
src/Java/README.md
for detailed Java build and run instructions, including JDK 17 toolchain setup and running thetestapp
.
Contributions are welcome! Please run dotnet test
before submitting a pull request and follow the coding conventions described in AGENTS.md
.
This project is licensed under the MIT License.