Path: redb-route/redb.Route.IbmMq/README.md Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.IbmMq/README.md ---- # redb.Route.IbmMq > Documentation and articles: IBM MQ (WebSphere MQ) transport for **redb.Route** ESB framework. Native MQI access via `IBMXMSDotnetClient` (IBM.WMQ + IBM.XMS) — queues, topics, transactions, RPC, message groups, SSL/TLS, and W3C telemetry. Consumers can poll (default) or receive **event-driven** via an XMS `MessageListener` (`receiveMode=listener`, sub-50 ms latency). [![NuGet](https://img.shields.io/nuget/v/redb.Route.IbmMq?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.Route.IbmMq) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../../LICENSE) ## Installation ```bash dotnet add package redb.Route.IbmMq ``` ## Quick Start ```csharp services.AddRedbRoute(route => { route.Services.AddRedbRouteIbmMq(); route.AddRouteBuilder(); }); ``` ```csharp public class MyRoutes : RouteBuilder { protected override void Configure() { From("wmq:DEV.QUEUE.1?host=mq-host&queueManager=QM1&channel=DEV.APP.SVRCONN") .Log("Received: ${body}") .To("wmq:ORDERS.OUT?host=mq-host&queueManager=QM1&channel=DEV.APP.SVRCONN"); } } ``` ## URI Format ``` wmq:{destination}?{options} ``` `{destination}` — queue or topic name (e.g. `DEV.QUEUE.1`, `EVENTS/ORDER`). ## Fluent DSL ```csharp // Queue (point-to-point) From(Wmq.Queue("DEV.QUEUE.1") .Host("mq-host") .QueueManager("QM1") .Channel("DEV.APP.SVRCONN") .User("app") .Password("passw0rd")) // Topic (pub/sub) From(Wmq.Topic("EVENTS/ORDER") .Host("mq-host") .QueueManager("QM1") .ConcurrentConsumers(4)) // Persistent send with JMS interop .To(Wmq.Queue("ORDERS.OUT") .Host("mq-host") .Persistent() .TargetClient(IbmMqTargetClient.Jms)) // Transacted From(Wmq.Queue("TXN.QUEUE") .Host("mq-host") .Transacted()) // RPC (request/reply) .To(Wmq.Queue("RPC.SERVICE") .Host("mq-host") .ReplyTo() .Timeout(10)) // SSL/TLS From(Wmq.Queue("SECURE.QUEUE") .Host("mq-host") .SslCipherSpec("TLS_RSA_WITH_AES_256_CBC_SHA256") .SslKeyRepository("/var/mqm/ssl/key")) ``` ## Event-Driven Receive (XMS Listener) By default the consumer **polls** with a blocking `MQGET`-`WAIT`. The IBM.WMQ managed .NET client carries an internal ~500 ms tick, so on an idle/low-traffic queue messages arrive ~250–500 ms after they were put. Setting `receiveMode=listener` switches to an **event-driven** receive built on **XMS .NET** (`IBM.XMS`), where the broker pushes messages into a `MessageListener` the instant they arrive — dropping delivery latency to **single-digit milliseconds**. (IBM.WMQ exposes no public async-consume API, so XMS is the only supported event-driven path on the managed .NET client.) ```csharp // URI From("wmq:ORDERS?host=mq-host&queueManager=QM1&channel=DEV.APP.SVRCONN&receiveMode=listener") // Fluent From(Wmq.Queue("ORDERS").Host("mq-host").QueueManager("QM1").Listener()) ``` It is **opt-in** — `Poll` remains the default, so existing routes are unchanged. The listener path honours the same consumer semantics as the poll path: - **Transacted** (`transacted=true`) — a `SESSION_TRANSACTED` session; commit on success, rollback (redeliver) on error, on the delivering session. A route-level `.Transaction()` block settles it as part of the route unit-of-work; without one the engine settles it directly. - **`concurrentConsumers=N`** — N XMS sessions on the shared connection (competing consumers, one in-flight per session for back-pressure). A topic clamps to a single subscriber. - **RPC reply**, **backout threshold**, and **W3C trace-context propagation** all work as on the poll path. - **Headers** — the same `redbIbmMq.*` MQMD metadata and application (user) headers as the poll path. User headers travel in the JMS `usr` folder, so they interoperate across IBM.WMQ, IBM.XMS and any JMS client. - **RPC client leg** — a producer doing request-reply (`replyTo=true`) with `receiveMode=listener` also receives the response event-driven (XMS listener on the reply queue), so the whole round-trip is fast (~16 ms warm vs the ~250–500 ms poll floor). The request is still sent over IBM.WMQ; only reply reception moves to XMS. A dynamic reply queue uses an XMS temporary queue. A dynamic reply queue (`replyTo=true` without `replyToQueue`, on the poll path and the listener path alike) is created from the model queue `temporaryModel` (IBM MQ's `TEMPMODEL`, default `SYSTEM.DEFAULT.MODEL.QUEUE`), so the connecting user needs `+dsp +get +put +inq` on that model queue (`SET AUTHREC PROFILE(SYSTEM.DEFAULT.MODEL.QUEUE) OBJTYPE(QUEUE) PRINCIPAL('app') AUTHADD(DSP,GET,PUT,INQ)`); the IBM MQ 9.4 developer image does not grant it to `app`, which gets `DEV.APP.MODEL.QUEUE` instead (`temporaryModel=DEV.APP.MODEL.QUEUE`). With `connectionFactory` the model is the factory's `TemporaryModel`. > The listener runs each route synchronously on the XMS dispatch thread (one in-flight message per session), > which is what provides natural back-pressure. Reverting to the poll path is a matter of flipping the option > back to `Poll` (or omitting it). ## Batch mode `batching=true` makes the consumer hand the route one exchange per batch, by the batch contract every broker of redb.Route follows. Poll receive mode only. - Each worker (`concurrentConsumers`) reads a batch with MQGET under its connection's syncpoint: up to `maxBatchMessages` (default 100), sent on once no message came for `pollTimeoutMs` (default 1000, restarted by every message) or once `batchingIntervalMs` has passed since the first message. - The body is a `List`, one message per MQ message with its own body and `redbIbmMq.*` headers, even for a batch of one; the size is `body.Count`. `redbIbmMq.Destination` and `redbIbmMq.QueueManager` are set on the batch message. The exchange is InOnly. `Split` over the body gives each part its message. - The batch is committed (MQCMIT) once after the route. A failed batch is backed out (MQBACK), the rule of a failed single message: every message returns to the queue with its backout count raised, and once it reaches `backoutThreshold` it goes to `backoutQueue` instead of into a batch. - A request (a message with a reply-to queue) cannot be answered from a one-way batch: it goes to `backoutQueue` in the batch's unit of work, with an error in the log and the endpoint statistics. `disableReplyTo=true` ignores the reply-to: such messages are batched and nobody replies (single mode too: no reply is sent). - A batch half collected when the consumer stops is backed out: its messages return to the queue. - The start fails for a batch option without `batching=true`, a value out of range, `receiveMode=listener`, `replyTo=true`, and, when the consumer starts, no backout queue (`backoutQueue`, the queue's BOQNAME) and no dead letter queue on the queue manager. ## Poison messages A consumer that reads under syncpoint (`transacted=true` in poll mode, or batch mode) backs a failed message out, and the message comes again with its backout count raised. It follows the provider's chain, as the IBM MQ classes for JMS do: once the backout count reaches the threshold, the message goes to the backout queue in the unit of work of its read, instead of to the route. - The threshold is `backoutThreshold`, else the input queue's BOTHRESH; the backout queue is `backoutQueue`, else the input queue's BOQNAME. The endpoint's options override the queue's attributes. - With a threshold and no backout queue, the message goes to the queue manager's dead letter queue (DEADQ), behind a dead letter header (MQDLH, reason MQRC_BACKOUT_THRESHOLD_REACHED), as the provider puts it there. - With a threshold and neither a backout queue nor a dead letter queue, the consumer does not start. - With no threshold anywhere (BOTHRESH 0 and no option), a message that always fails comes back after every backout until something stops it: give the route an error handler (`OnException`, a dead letter channel) that decides its end. - In listener mode the XMS client runs the same chain itself on the queue's BOTHRESH and BOQNAME (`backoutThreshold` below BOTHRESH applies as above). The client moves the message with its context: the application's user needs PASSALL (and PUT) on the backout queue and the dead letter queue, or the move fails with MQRC_NOT_AUTHORIZED (2035) and the message stays on the input queue. ### The pause after a backout IBM MQ does not delay a backed-out message: the next MQGET takes it again at once. After a backout (a failed message with `transacted=true`, a failed batch, a poison message whose move failed) the consumer pauses for `backoutDelay` milliseconds (default 1000): none of its workers starts another MQGET until the pause has passed, and a later backout extends it. `backoutDelay=0` keeps no pause, as before the option. - This option is redb's addition: Apache Camel and the IBM MQ classes for JMS have no such option. - Poll and batch modes. In listener mode the XMS client sets the tempo and the option does not act. - A worker already waiting in MQGET when another worker backs out is not held back: with `concurrentConsumers` above 1 that worker can take the message before the pause ends. - The consumer's own stop backs out its message in flight without a pause. ## A lost connection Every connection of this connector runs on the Route connection supervisor: the schedule, the log lines, the health and the connection events are the ones described under "Lost connections" in the redb.Route README, set once for the context under `RedbRoute:Reconnect` (by default: first attempt after 1 s, then twice as long each time up to 30 s, one attempt given up after 30 s). The reason codes taken as a lost connection: `MQRC_CONNECTION_BROKEN`, `MQRC_Q_MGR_QUIESCING`, `MQRC_CONNECTION_QUIESCING`, `MQRC_Q_MGR_STOPPING`, `MQRC_CONNECTION_STOPPING`, `MQRC_HCONN_ERROR`, `MQRC_Q_MGR_NOT_AVAILABLE` and `MQRC_CALL_INTERRUPTED`. While a connection is lost the endpoint's health is `Warning`, and `Critical` once an attempt to reconnect failed; a consumer route whose endpoint is `Critical` is `Unhealthy` in the route health check. Each connection is supervised on its own and named in the health reason and the events: `wmq:ORDERS consumer worker 2`, `wmq:ORDERS listener`, `wmq:ORDERS` for the producer. **Poll consumer (single or batch).** A worker does not end: it closes what is left of its connection and connects again on the schedule until it is connected or the consumer stops; a connection an attempt opens after it was given up is closed. What the worker held under syncpoint the queue manager backed out, so those messages are read again. **Listener consumer (`receiveMode=listener`).** The XMS connection's exception listener reports the loss; the consumer closes the connection with its sessions and opens a new one, with all its sessions, on the schedule. Messages in flight on the broken sessions are not settled: under `transacted=true` they return to the queue. **Producer.** A producer whose connection is lost fails the send that found it out and fails at once every request-reply call still waiting for its reply on that connection, with the poll reply loop and with the XMS reply receiver (`receiveMode=listener`) alike. Its next send reconnects first (a new connection, the destination, and for request-reply the reply queue or a new temporary queue), one bounded attempt: a send that comes before the next attempt is due fails at once and says when it is due. A transacted send (`.Transacted()` or `transacted=true`) whose puts or MQCMIT meet the lost connection reports it too, so the next send reconnects; a connection lost during MQCMIT itself leaves the outcome in doubt, and a warning line says so. **A failed send is not resent.** A put that failed because the connection broke may or may not have reached the queue manager; whether to send again (and accept a possible duplicate) is the route's decision, through its error handler or redelivery. A connect that reaches a queue manager still starting through a port proxy (a Docker published port, for one) can hang in the managed client, and in our tests every later connect of the same process then waited behind it for minutes. With the queue manager on host networking, or a listener the client reaches directly, this was not seen. ## A list body A list of `IMessage` (a batch consumer's body, for one) is sent element by element, each element its own MQ message with its own body and headers, none of the exchange's, in one unit of work: every MQPUT under syncpoint and one MQCMIT, or MQBACK and nothing goes. Inside a `.Transacted()` block they join the producer's batch for the block. A plain list (one whose text would be its type name) is refused, and so is any list at a request-reply producer (`replyTo=true`). ## Options Reference ### Connection | Option | Default | Description | |---|---|---| | `host` | `localhost` | Queue manager host | | `port` | `1414` | MQ listener port | | `channel` | `DEV.APP.SVRCONN` | Server-connection channel | | `queueManager` | `QM1` | Queue manager name | | `user` | — | Auth username | | `password` | — | Auth password | | `clientId` | — | Client identifier | | `connectionFactory` | — | Name of an `IbmMqConnectionFactory` in the context registry; takes priority over the inline connection options | ### Destination | Option | Default | Description | |---|---|---| | `destinationType` | `Queue` | `Queue` or `Topic` | ### Consumer | Option | Default | Description | |---|---|---| | `receiveMode` | `Poll` | `Poll` (MQGET-WAIT) or `Listener` (event-driven XMS, <50 ms) | | `concurrentConsumers` | `1` | Parallel consumers | | `waitInterval` | `5000` | MQGET wait (ms), poll mode only | | `batching` | `false` | Batch mode (poll receive mode); see [Batch mode](#batch-mode) | | `maxBatchMessages` | `100` | Largest batch | | `pollTimeoutMs` | `1000` | Batch mode: idle timeout of a batch (ms) | | `batchingIntervalMs` | — | Batch mode: hard limit of a batch from its first message (ms) | | `disableReplyTo` | `false` | Do not act on a request's reply-to: no reply, and a batch takes it | | `backoutThreshold` | the queue's BOTHRESH | With `transacted=true` (poll mode) or in batch mode: a message backed out this many times goes to the backout queue instead of the route, in the unit of work of its read (0 on both = off); see [Poison messages](#poison-messages) | | `backoutQueue` | the queue's BOQNAME | Backout queue; without one, the queue manager's dead letter queue | | `backoutDelay` | `1000` | Pause after a backout (ms) before the consumer reads again, poll and batch modes; 0 = none; redb's addition, not in Apache Camel; see [The pause after a backout](#the-pause-after-a-backout) | | `selector` | — | Message selector | | `convert` | `true` | Apply MQGMO_CONVERT | ### Producer | Option | Default | Description | |---|---|---| | `persistence` | `AsQDef` | `Persistent`, `NonPersistent`, `AsQDef` | | `priority` | `-1` | Priority (0–9, -1 = queue default) | | `expiry` | `-1` | Expiry (tenths/sec, -1 = unlimited) | | `targetClient` | `Jms` | `Jms` (with MQRFH2) or `Mq` (raw MQMD) | | `messageType` | `Datagram` | `Datagram`, `Request`, `Reply`, `Report` | ### Transactions | Option | Default | Description | |---|---|---| | `transacted` | unset | Consumer: `true` gets under syncpoint (MQCMIT/MQBACK). Producer: unset follows an enclosing `.Transacted()` block (the put waits for the database commit), `false` puts at once, `true` requires a block. A request-reply producer always puts at once and refuses `true` | The deferred puts of one producer in a block are committed in one unit of work: every put under syncpoint, then one MQCMIT, so they arrive together, in order, or not at all (a failed put backs them all out). The producer's batches take turns on its connection, because a unit of work belongs to the connection. ### RPC | Option | Default | Description | |---|---|---| | `replyTo` | `false` | Enable request/reply | | `replyToQueue` | — | Reply queue (or dynamic temp) | | `replyToQueueManager` | — | Reply QM | | `temporaryModel` | `SYSTEM.DEFAULT.MODEL.QUEUE` | Model queue of the dynamic reply queue (IBM MQ `TEMPMODEL`) | | `preserveMessageQos` | `false` | Keep the `redbIbmMq.ReplyToQueue` and `redbIbmMq.ReplyToQueueManager` headers on an ordinary put | | `timeout` | `30` | RPC timeout (seconds) | | `correlationPattern` | `MsgId` | `MsgId` or `CorrelId` | ### SSL/TLS | Option | Default | Description | |---|---|---| | `sslCipherSpec` | — | CipherSpec name | | `sslCertLabel` | — | Certificate label | | `sslPeerName` | — | Peer DN pattern | | `sslKeyRepository` | — | Key repo path (.kdb) | | `sslKeyResetCount` | `0` | Key renegotiation (bytes) | ### Advanced | Option | Default | Description | |---|---|---| | `cCSID` | `1208` | Coded Character Set ID | | `mqmdWriteEnabled` | `false` | Write MQMD from headers | | `mqmdReadEnabled` | `true` | Read MQMD into headers | ## Headers All IBM MQ metadata headers are prefixed with `redbIbmMq.`: - `redbIbmMq.MsgId` — message ID (hex) - `redbIbmMq.CorrelId` — correlation ID (hex) - `redbIbmMq.Format` — MQMD format - `redbIbmMq.Persistence` — persistence flag - `redbIbmMq.Priority` — priority - `redbIbmMq.Expiry` — expiry - `redbIbmMq.ReplyToQueue` — reply-to queue. Not carried on by an ordinary (not request-reply) put unless `preserveMessageQos=true`: a message consumed with a sender's reply-to and forwarded here does not make another consumer answer into a queue of another system, as in Apache Camel's JMS. The correlation id is always carried; a request-reply put sets its own reply-to queue. - `redbIbmMq.MsgType` — message type - `redbIbmMq.BackoutCount` — backout count - ... and more (see `IbmMqHeaders` class) ### Header filter strategy The other exchange headers travel in one JSON-encoded message property (MQ property names forbid hyphens), as text; the consumer unpacks them on the poll and the XMS path alike, and a request-reply carries them both ways. `headerFilterStrategy=#name` names an `IHeaderFilterStrategy` in the registry that decides which headers cross, as in Apache Camel: outgoing for a request and a consumer's reply, incoming for a delivery and the reply a request-reply producer receives. It replaces the default, `IbmMqHeaderFilterStrategy` (keeps `redbIbmMq.*` back), entirely; derive from that class to add to it. MQMD fields, `targetClient=Mq` (no properties at all) and the trace context are not the strategy's. ```csharp ctx.AddToRegistry("correlationOnly", new DefaultHeaderFilterStrategy { OutFilter = ["Correlation-ID"], FilterOnMatch = false, // a whitelist: only the listed headers go out }); // wmq:ORDERS.Q?queueManager=QM1&headerFilterStrategy=#correlationOnly ``` ## Telemetry On the `redb.Route` activity source (`AddSource("redb.Route")`). The W3C context travels in the MQRFH2 user properties `traceparent`, `tracestate` and `baggage` (not with `targetClient=Mq`, which sends no properties). - **Consumer**, poll and listener alike. One `Consumer` span per message, `{destination} receive`, over the whole unit of work. Its parent is the sender's `traceparent`; without one — a message with no properties included — it is a root, never a child of the activity the receive loop inherited from whoever started the routes. The sender's baggage is back on it, the route's spans are its children, and a failed route marks it an error. - **Producer.** One `Producer` span per send, `{destination} publish`; an error when the send fails. The message carries the context of this span. - `RouteEngineOptions.EnableTelemetry = false` opens neither span. A context that came in still goes out. Tags: `messaging.system` = `wmq`, `messaging.operation` = `receive` / `publish`, `messaging.destination.name`, `messaging.ibmmq.queue_manager`, `messaging.message.id` (MQMD MsgId, poll path), `redb.route.endpoint`. ## Docker (Dev/Test) ```bash docker compose -f docker-compose.tests.yml up -d ibmmq ``` Default dev credentials: - **Host**: `localhost:1414` - **Queue Manager**: `QM1` - **Channel**: `DEV.APP.SVRCONN` - **User**: `app` / `passw0rd` - **Web Console**: `https://localhost:9443/ibmmq/console` (`admin` / `passw0rd`) Pre-created queues: `DEV.QUEUE.1` … `DEV.QUEUE.5`, `DEV.DEAD.LETTER.QUEUE`. ## Named connection factory Keep credentials out of the route URI: register a factory in the context registry and reference it by name. A set-but-unknown name fails loud at startup, when the endpoint is created: a typo can never silently fall back to inline URI parameters. ```csharp context.AddToRegistry("prod", new IbmMqConnectionFactory { Host = "mq.internal", QueueManager = "QM1", Channel = "DEV.APP.SVRCONN", User = "app", Password = secrets.MqPassword, }); // wmq://DEV.QUEUE.1?connectionFactory=prod ``` The factory describes the whole connection: host, port, channel, queue manager, user and password, client name, transport, TLS settings and CCSID all come from it, for the MQ-classes connections and the XMS listener alike. Connection options written on the same URI are not used. Endpoints naming the same factory share one pooled connection; without `connectionFactory` the inline options describe the connection. ## Concurrency The default is **1** concurrent consumer — the industry norm (Camel, Spring, the Azure SDK all ship 1): a single consumer preserves ordering and your handlers need no thread safety. Parallelism is an explicit opt-in: ``` concurrentConsumers=4 # a fixed worker count concurrentConsumers=auto # max(CPU count, 2) — the NServiceBus formula ``` Anything else — `0`, a negative, a typo — fails at endpoint creation naming the option (the old int-typed option silently fell back to 1). Raising the value trades ordering for throughput: messages from the same queue are processed out of order, and your processors must be safe to run in parallel. IBM MQ specifics: `concurrentConsumers` on a TOPIC clamps to 1 — parallel non-durable subscriptions would each receive a full copy of every message (duplicate delivery), not share the load. Use a QUEUE destination for competing consumers.