Skip to main content

Migrate from MassTransit

Start with one endpoint and run both systems on separate destinations during verification. This is an application migration, not a compatible replacement for MassTransit envelopes or persisted state. The source model below follows MassTransit's consumer documentation.

Map the common path​

MassTransit call siteRelayer equivalent
IConsumer<T>.Consume(ConsumeContext<T>)IHandler<T>.HandleAsync(T, MessageContext, CancellationToken)
Publish or endpoint sendISender.SendAsync with one explicit typed route to a native topic or queue
Consumer/endpoint registrationAddMessageTypesFromThisAssembly() and typed Consume(...).Handler<THandler>()

For a consumer that previously read context.Message, use the message parameter directly:

using Microsoft.Extensions.Logging;
using Relayer;

[Message("orders.placed", Version = 1)]
public sealed record OrderPlaced(string OrderId);

public sealed class OrderPlacedHandler(ILogger<OrderPlacedHandler> logger) : IHandler<OrderPlaced>
{
public ValueTask HandleAsync(OrderPlaced message, MessageContext context, CancellationToken cancellationToken)
{
logger.LogInformation("Received {OrderId}", message.OrderId);
return ValueTask.CompletedTask;
}
}

Use the complete Service Bus web API sample for host, route, source generation and consumer registration. A route to a queue has native point-to-point behavior; a topic's subscriptions or Kafka consumer groups supply fan-out. SendAsync does not discover subscribers or create a MassTransit-style topology by convention. Configure native topology explicitly.

Preserve durability and operational behavior​

  1. Assign stable [Message] names and source-generated JSON metadata. Old MassTransit messages cannot be assumed to deserialize as Relayer's CloudEvents binding. Drain old destinations or use an application-owned bridge that reads through the old client and sends a new Relayer message. Preserve business identifiers and make the bridge idempotent.
  2. Translate retry/redelivery intent with the selected transport's failure capabilities. Retry counts, dead-letter destinations and delay support are explicit; do not copy middleware settings without checking native limits.
  3. Replace database outbox use with the implemented PostgreSQL EF outbox, direct dispatch and recovery. For a database consumer, configure the EF inbox boundary. Neither implementation imports MassTransit database rows.
  4. Re-test native concurrency, ordering, duplicate delivery, poison handling and restart with the testing tools. Keep old consumers running until their queues and pending outbox entries are drained, then switch producers and retire the bridge.

Features requiring redesign​

Relayer has explicit saga state transitions, timeouts and request/response; these do not import state machines, correlation conventions or persisted MassTransit state. Port each workflow and verify its database boundary. Routing slips and job-consumer parity are unavailable; do not treat them as implemented. With Kafka-to-Kafka exactly-once, a consumer can commit its offsets and handler sends routed through the same Kafka transport in one native transaction.

By default, Kafka startup checks that required topics exist. Set TopologyMode.Provision to create missing topics at startup. Both modes check settings on explicitly declared topics. See Kafka topic topology.