Path: redb-route/redb.Route.IbmMq/IbmMqXmsAckAction.cs 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/IbmMqXmsAckAction.cs ---- using IBM.XMS; using Microsoft.Extensions.Logging; using redb.Route.Abstractions; namespace redb.Route.IbmMq; /// /// Deferred acknowledgement for the XMS (event-driven) receive path: commit/rollback of a /// transacted XMS (JMS SESSION_TRANSACTED), the XMS analogue of /// (which wraps MQCMIT/MQBACK on an IBM.WMQ connection). /// /// Session affinity. A transacted JMS session commits/rolls back on the same session /// that delivered the message. Because the XMS engine runs the whole route synchronously inside the /// listener callback, both the route's transaction unit-of-work and the engine's own settle call /// execute on that session's dispatch thread — so this action always commits the session that /// delivered the message. (JMS permits commit/rollback inside onMessage; only /// creating/closing the session there is forbidden.) /// /// /// Idempotent. Whichever settles first wins and the other is a no-op: a route-level /// .Transaction() block (via TransactedProcessor) settles the action as part of the /// route unit-of-work; if the route has no transaction block, the engine settles it directly after /// the route returns. This makes transacted listener mode correct with or without a route /// transaction, and prevents a double commit/rollback when both paths are present. /// /// internal sealed class IbmMqXmsAckAction : ITransactedAction { private readonly ISession _session; private readonly ILogger? _logger; private int _settled; // 0 = pending, 1 = committed/rolled back public IbmMqXmsAckAction(ISession session, ILogger? logger) { _session = session; _logger = logger; } /// True once the session has been committed or rolled back through this action. public bool Settled => Volatile.Read(ref _settled) != 0; /// public Task Commit(CancellationToken ct = default) { if (Interlocked.CompareExchange(ref _settled, 1, 0) != 0) return Task.CompletedTask; // already settled — no-op _session.Commit(); _logger?.LogDebug("IBM MQ XMS ack committed (session.Commit)"); return Task.CompletedTask; } /// public Task Rollback(CancellationToken ct = default) { if (Interlocked.CompareExchange(ref _settled, 1, 0) != 0) return Task.CompletedTask; // already settled — no-op _session.Rollback(); _logger?.LogDebug("IBM MQ XMS nack (session.Rollback)"); return Task.CompletedTask; } }