How do I set the CorrelationId when I publish a message?

To set the CorrelationId on a message, use the Command interface to create the appropriate publish command and then use the executeAsync method on the client to send the command to AMPS.

For example, the following snippet shows one way to use this interface in Java:

Command publishCommand = new Command("publish").setTopic("myTopic");

// You can reuse the publish command for any number of messages
// by setting the data and correlation ID just before you publish


// The null message handler here means that the command
// does not expect a stream of messages in response, so
// does not need to have a message handler set up.


One important point: the CorrelationId can only contain characters that are valid in Base64 encoding. Otherwise, AMPS may report a parse error when trying to interpret the publish command.

See the Developer Guide for your client of choice for more information on the Command interface and recipes for using the Command interface with AMPS.

Keywords: publish, CorrelationId, setting publish fields

Last updated