Path: redb-route/redb.Route.IbmMq/IbmMqConnectionLoss.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/IbmMqConnectionLoss.cs
----
using IBM.WMQ;
using Microsoft.Extensions.Logging;
namespace redb.Route.IbmMq;
///
/// What the IBM MQ consumer and producer share about a lost connection: which reason codes say it is gone, and how to
/// close what is left of it. The schedule of reconnect attempts and the bound of one attempt are the core's
/// .
///
internal static class IbmMqConnectionLoss
{
///
/// The reason codes that say a connection is gone or going: the queue manager quiesces, stops or restarts, the
/// network cut the connection, or the call was interrupted while the client reconnected. The owner reconnects on
/// them instead of using a dead handle.
///
internal static bool IsConnectionLost(int reasonCode) => reasonCode
is MQC.MQRC_CONNECTION_BROKEN or MQC.MQRC_Q_MGR_QUIESCING or MQC.MQRC_CONNECTION_QUIESCING
or MQC.MQRC_Q_MGR_STOPPING or MQC.MQRC_CONNECTION_STOPPING or MQC.MQRC_HCONN_ERROR
or MQC.MQRC_Q_MGR_NOT_AVAILABLE or MQC.MQRC_CALL_INTERRUPTED;
/// Disconnects a connection that is lost or no longer wanted; errors are logged at debug level only.
internal static void DisconnectQuietly(MQQueueManager? qm, ILogger? logger)
{
if (qm is null) return;
try { if (qm.IsConnected) qm.Disconnect(); }
catch (Exception ex) { logger?.LogDebug(ex, "IBM MQ: error disconnecting a lost connection"); }
}
}