Skip to content

BabelQueue/babelqueue-dotnet-masstransit

BabelQueue for MassTransit

CI NuGet License: MIT

Polyglot Queues, Simplified. A MassTransit adapter that makes your MassTransit services produce and consume the canonical BabelQueue envelope — so they exchange messages with the Laravel, Symfony, Python, Go, Node and Java SDKs over one strict JSON format.

This is the MassTransit adapter on top of BabelQueue.Core: a System.Text.Json converter (byte-for-byte canonical envelopes), an ergonomic publisher and configuration helpers. The full standard is documented at babelqueue.com.

Installation

dotnet add package BabelQueue.MassTransit

Targets .NET 8; requires MassTransit 8+.

How it works

MassTransit normally wraps messages in its own envelope. This adapter registers a System.Text.Json converter that encodes/decodes the canonical BabelQueue envelope via the core codec and switches the bus to MassTransit's raw JSON serializer — so the bytes on the wire are exactly what every other BabelQueue SDK produces and consumes.

using BabelQueue.MassTransit;

builder.Services.AddMassTransit(x =>
{
    x.UsingRabbitMq((context, cfg) =>
    {
        cfg.UseBabelQueueEnvelopes();   // canonical envelope on the wire (raw JSON)
        cfg.ConfigureEndpoints(context);
    });
});

builder.Services.AddBabelQueuePublisher(defaultQueue: "orders");

Produce

using BabelQueue.MassTransit;

public class Orders(BabelQueuePublisher babelQueue)
{
    public Task Create() =>
        babelQueue.PublishAsync(
            "urn:babel:orders:created",
            new Dictionary<string, object?> { ["order_id"] = 1042L },
            "orders");
}

The queue receives the canonical envelope:

{
  "job": "urn:babel:orders:created",
  "trace_id": "",
  "data": { "order_id": 1042 },
  "meta": { "id": "", "queue": "orders", "lang": "dotnet", "schema_version": 1, "created_at": 1749132727000 },
  "attempts": 0
}

Consume

A consumer receives the decoded Envelope; route by URN:

using BabelQueue;
using MassTransit;

public class OrderConsumer : IConsumer<Envelope>
{
    public Task Consume(ConsumeContext<Envelope> context)
    {
        var envelope = context.Message;
        if (!EnvelopeCodec.Accepts(envelope))
            return Task.CompletedTask;

        switch (EnvelopeCodec.Urn(envelope))
        {
            case "urn:babel:orders:created":
                // handle envelope.Data, envelope.TraceId …
                break;
        }
        return Task.CompletedTask;
    }
}

Standalone converter

The converter works with any System.Text.Json usage (not just MassTransit):

var options = new JsonSerializerOptions().AddBabelQueueEnvelopes();
string wire = JsonSerializer.Serialize(envelope, options); // == EnvelopeCodec.Encode(envelope)

License

MIT © Muhammet Şafak

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages