Custom message identifier - sequenceNumber vs applicationMessageId

Recently I had a requirement to specify a unique identifier for each message that I was publishing to the broker. When inspecting the API reference, I found that there are two fields that can be used for this purpose - the applicationMessageId and the sequenceNumber on the message. Both are similar but have some subtle differences:

  • Both fields when set on a message will propagate through to the consumer and can be retrieved via their appropriate getter method
  • The "sequenceNumber" takes an unsigned int as an argument hence is useful when your identifier is a number. The "applicationMessageId" takes a char * and hence is useful when you want to specify a GUID
  • The "applicationMessageId" is a string that also corresponds to JMSMessageID. You can use this if you have a JMS consumer and want the message identifier to be available in the JMSMessageID field.
  • The message-sequence number can be automatically set by the Solace API for you - you can do this by enabling the session property SOLCLIENT_SESSION_PROP_GENERATE_SEQUENCE_NUMBER. However, if the application specifies a custom sequence number with solClient_msg_setSequenceNumber, solClient_msg_setSequenceNumber will take precedence.
  • Finally if you do not want to use any of these fields, you can always define a custom header for your message and set the message identifier in that!

In any case, these identifiers are independant of the internal message-id that the Solace broker adds to each message received, to ensure that messages are delivered to consumers in the same sequence that they are received by the broker.