how to set correlation id via Message Service Api

jainullabm
jainullabm Member Posts: 3
edited February 4 in PubSub+ Event Broker #1

how to set correlation id via Message Service Api, i tried using solace.messaging.message.correlation-id while preparing message builder, but always creating REQ0,REQ1 etc, could n't able to get my custom generated correlation id

I need this correlation id for Req-Reply pattern, here the sample code

outboundMessage = messageBuilder.withProperty(SolaceProperties.MessageProperties.CORRELATION_ID,messageKey).build(messageContent);

inboundMessage = requestReplyMessagePublisher.publishAwaitResponse(outboundMessage, Topic.of(solaceMessagingSession.getLocalTopic()),

    			 CmSolaceConstants.PUB_REQUEST_TIMEOUT_MS);

Answers

  • mpatel
    mpatel Member, Employee Posts: 17 Solace Employee
    edited February 4 #2

    @jainullabm

    Looking at the code, I assume you are using Java API.

    One of the option is to pass the additionalMessageProperties while publishing a message…

    or

    using the OutboundMessageBuilder.fromProperties(Properties properties) method

      //MessagingService servicce = ....
      final OutboundMessageBuilder messageBuilder = service.messageBuilder();
      final OutboundMessage m = messageBuilder.build(messagePayload);
    
      final Properties properties = new Properties();
      properties.setProperty(MessageProperties.CORRELATION_ID, correlationId);
      properties.setProperty(MessageProperties.APPLICATION_MESSAGE_TYPE, messageType);
      properties.setProperty(customKey, myValue);
    
    
      publisher.publish(m, t1, properties);
          
    
  • jainullabm
    jainullabm Member Posts: 3

    Thank you, What will be the Message type here? Persistent/non-persistent or data type like string?

  • jainullabm
    jainullabm Member Posts: 3

    Thank you , Its working perfect , i can able to publish message with custom key now