v7 Hosting, handlers, OpenTelemetry and more

Messaging between .NET services, without the boilerplate.

Commands, events, requests and responses over RabbitMQ, Kafka, NATS, ActiveMQ, Azure Service Bus or Amazon SQS, with handlers, awaitable requests and Reactive Extensions streams.

$ dotnet add package Obvs
Program.cs
builder.Services.AddObvs(obvs => obvs
    .AddService<IOrderMessage>("orders", service => service
        .UseRabbitMq(options => options.Uri = new Uri("amqp://localhost:5672"))
        .HandleCommand<PlaceOrder>(async (command, context, ct) =>
            await context.PublishAsync(new OrderPlaced(command.OrderId), ct))
        .HandleRequest<GetQuote, Quote>((request, context, ct) =>
            Task.FromResult(new Quote(request.Sku, 9.99m)))));

// From anywhere with the bus
await client.SendAsync(new PlaceOrder("o-1"), ct);
var quote = await client.RequestAsync(
    new GetQuote("sku-1"), TimeSpan.FromSeconds(5), ct);
Transports RabbitMQ Kafka NATS NATS JetStream ActiveMQ Azure Service Bus Amazon SQS & SNS NetMQ

Why Obvs

Define the messages. Handle them. Configure the rest.

Writing code to connect two processes involves a lot of boilerplate, and every new service or message type repeats it. Obvs takes care of it. Define a service's messages, choose its transport, and handle them: the rest is configuration you can change without touching your handlers.

Hosted with dependency injection

Every transport configured the same way, from configuration or code. The bus starts and stops with the host.

Handlers

Run in a DI scope, settle messages on transports that keep them, and take a maximum concurrency.

Requests and streams

Await a request's response, and read the bus's streams as Rx observables or IAsyncEnumerable.

Serialization

System.Text.Json by default, or Newtonsoft JSON, MessagePack or ProtoBuf, any of them gzipped.

OpenTelemetry

Traces and metrics, with each message's trace carried from sender to handler.

Checked at startup

Every configuration problem reported at once, each with its fix.

Analyzers

Catch common mistakes as you type, with code fixes, built into the Obvs package.

Testing

An in-memory transport and test harness that waits for messages without fixed delays.

Contracts and agents

Each service's contract as an AsyncAPI document, and an MCP server so agents can inspect and drive a development bus.

Quick start

From nothing to a running service

Add the packages, define the service's messages, host it, and use it.

Add the packages

Obvs, and a transport.

dotnet add package Obvs
dotnet add package Obvs.RabbitMQ

Define your service's messages

Each is a command, an event, a request or a response.

// Every message of a service implements its interface,
// and is one of ICommand, IEvent, IRequest or IResponse.
// A request names the response that answers it.
public interface IOrderMessage : IMessage { }

public record PlaceOrder(string OrderId) : IOrderMessage, ICommand;

public record OrderPlaced(string OrderId) : IOrderMessage, IEvent;

public record GetQuote(string Sku) : IOrderMessage, IRequest<Quote>
{
    public string RequestId { get; set; }
    public string RequesterId { get; set; }
}

public record Quote(string Sku, decimal Price) : IOrderMessage, IResponse
{
    public string RequestId { get; set; }
    public string RequesterId { get; set; }
}

Host the service

It handles commands and requests, and publishes events.

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddObvs(obvs => obvs
    .AddService<IOrderMessage>("orders", service => service
        .UseRabbitMq(options => options.Uri = new Uri("amqp://localhost:5672"))
        .HandleCommand<PlaceOrder>(async (command, context, ct) =>
        {
            // ... place the order, then tell whoever's interested
            await context.PublishAsync(new OrderPlaced(command.OrderId), ct);
        })
        .HandleRequest<GetQuote, Quote>((request, context, ct) =>
            Task.FromResult(new Quote(request.Sku, 9.99m)))));

await builder.Build().RunAsync();

Use it from anywhere with the bus

Send commands and await requests' responses.

var client = app.Services.GetRequiredService<IServiceBusClient>();

await client.SendAsync(new PlaceOrder("o-1"), ct);

var quote = await client.RequestAsync(new GetQuote("sku-1"), TimeSpan.FromSeconds(5), ct);

Docs

Learn more

Guides on GitHub, each snippet in them compiled and tested.

Coming from v6?

v6 and v7 apps work together on the same broker, so you can move one app at a time.