Skip to main content

Migrate from CAP

CAP's messaging API uses named publications and subscriptions. Its transaction model targets eventual consistency rather than a distributed ACID transaction. Preserve that boundary when moving to Relayer: commit business changes and an outgoing row locally, then dispatch to the broker.

Map publication and subscription​

CAPRelayer
ICapPublisher.PublishAsync("orders.placed", message)ISender.SendAsync(message, cancellationToken) with Send<OrderPlaced>(destination)
[CapSubscribe("orders.placed")] methodExplicit Consume(destination, consumer => consumer.Handler<OrderPlacedHandler>())
Publication name and subscriber groupStable [Message("orders.placed", Version = 1)] plus separately configured native destination/group

The wire identity and broker destination are separate. A CAP publication name is not enough to configure Relayer's route or deserialize old records. Add concrete contracts through AddMessageTypesFromThisAssembly() and implement IHandler<T>.HandleAsync. Start from the runnable Kafka EF outbox sample, whose POST endpoint does:

await using var transaction = await db.Database.BeginTransactionAsync(cancellationToken);
db.Orders.Add(new Order { Id = id });
await sender.SendAsync(new OrderPlaced(id), cancellationToken);
await db.SaveChangesAsync(cancellationToken);
await transaction.CommitAsync(cancellationToken);

This is the sample's real call site: its PostgreSQL context has AddRelayerOutbox interceptors, and direct dispatch plus maintenance use the same database. With an outbox registered, ordinary SendAsync throws outside an active transaction or explicit context selection. SendViaOutboxAsync additionally requires an outbox registration; use SendWithoutOutboxAsync only for intentional direct sends. See EF transaction enlistment for setup and failure semantics.

Check storage and subscriber behavior​

Relayer's EF Core outbox and inbox integrations currently support only PostgreSQL/Npgsql. With ADO.NET or Dapper, SQL Server and MySQL can enqueue messages in the same transaction as business writes. Use fresh Relayer tables so Relayer can manage its own message identities, row ownership and retention.

For consumers that write to a database, register the inbox for your provider and data access API. With EF Core, use the PostgreSQL EF Core inbox. With ADO.NET or Dapper, use the SQL Server inbox or MySQL inbox. Each inbox commits the receipt and business writes together. Transport settlement follows durable work. Inbox deduplication is scoped to the stored consumer/message identity; business operations must still tolerate duplicates from bridges or publishers that assign a new identity. Match native consumer groups or subscriptions explicitly; no attribute scanning or CAP subscriber group discovery occurs.

Configure failure handling rather than assuming CAP retry defaults. CAP callback names do not translate automatically; model an explicit response message or use the implemented request/response API after checking its timeout and routing constraints. CAP dashboard/storage history compatibility is unavailable. Scheduled delivery depends on the selected native transport or configured outbox fallback. Kafka receive parallelism processes different keys concurrently while preserving offset order for records with the same key within a partition by default.

Drain before switching​

Finish CAP's pending published/received work and retries with the original system. If old producers must coexist, use a bridge that receives with CAP and sends the new typed Relayer contract to separate destinations. Reusing JSON bodies alone does not preserve headers, identity or subscription behavior. Test rollback, duplicate receipt, crash recovery and poison messages against the actual broker and database before switching producers. The testing guide describes the harness and integration boundary.