Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Modernization
Samples

Native integration

Component: IBM MQ Transport

The IBM MQ transport uses standard IBM MQ message structures, making it possible to exchange messages between NServiceBus endpoints and native IBM MQ applications.

Message structure

NServiceBus messages on IBM MQ consist of a standard message descriptor (MQMD) and custom properties stored in MQRFH2 headers.

MQMD fields

The transport maps NServiceBus concepts to the following MQMD fields on send:

MQMD fieldUsage
MessageIdSet from the NServiceBus.MessageId header. Accepts a GUID or a hex string up to 24 bytes.
CorrelationIdSet from the NServiceBus.CorrelationId header. Accepts a GUID or a hex string up to 24 bytes.
MessageTypeAlways MQMT_DATAGRAM
PersistencePersistent by default; non-persistent if NonDurableMessage header is set
ExpirySet from the time-to-be-received setting; unlimited if not specified
ReplyToQueueNameSet from the NServiceBus.ReplyToAddress header

NServiceBus headers

All NServiceBus headers are stored as MQRFH2 message properties. Property names are escaped because IBM MQ only allows alphanumeric characters and underscores in property names. The escaping rules are:

  • Underscores are doubled: _ becomes __
  • Other special characters are encoded as _xHHHH (e.g., . becomes _x002E)

Receiving from non-NServiceBus senders

When a message arrives from a native IBM MQ application that does not set MQRFH2 properties, the transport promotes the following MQMD fields to NServiceBus headers. Promotion only occurs when the corresponding NServiceBus header is not already present, so NServiceBus-originated messages are unaffected.

MQMD fieldNServiceBus headerNotes
MessageIdNServiceBus.MessageIdEncoded as an uppercase hex string
CorrelationIdNServiceBus.CorrelationIdEncoded as an uppercase hex string
ReplyToQueueNameNServiceBus.ReplyToAddressTrimmed of whitespace; ignored if empty
PersistenceNServiceBus.NonDurableMessageSet to True when persistence is NOT_PERSISTENT
ExpiryNServiceBus.TimeToBeReceivedConverted from tenths of seconds; ignored when unlimited

This enables native senders to rely on standard MQMD fields for identity and routing without requiring knowledge of the NServiceBus header format.

Sending messages from native applications

To send a message to an NServiceBus endpoint from a native IBM MQ application:

  1. Put a message on the endpoint's input queue.
  2. Set the message body to a serialized representation (e.g., JSON).
  3. Set the following MQRFH2 properties as a minimum:
Property nameDescription
NServiceBus_x002EEnclosedMessageTypesThe fully qualified .NET type name of the message
NServiceBus_x002EContentTypeThe MIME type of the body (e.g., application/json)
NServiceBus_x002EMessageIdA unique identifier (typically a GUID)

Receiving messages in native applications

Native applications can consume messages from queues that NServiceBus publishes or sends to. The message body contains the serialized payload, and NServiceBus headers are available as MQRFH2 properties.

To read headers, use the nsbhdrs manifest property to enumerate all header names, and unescape property names by replacing __ with _ and _xHHHH with the corresponding character.