Replay from Message ID - How to use it!

marc
marc Member, Administrator, Moderator, Employee Posts: 914 admin
edited January 2022 in PubSub+ Event Broker #1

Hey everyone,
The recent v9.9 release of the PubSub+ Event Broker and the API releases that came with it now support the ability to trigger replay from a specific message id. I just wanted to share some info on how to use it with some of the different APIs!

Note that the Message ID is in available in the header of each Solace Message and each Solace SMF API allows you to easily retrieve it.

Useful resources

Using Python for Replay from Message ID

rgmid = "rmid1:096b4-e39eaab3209-00000000-0000002d"
reply_strategy = ReplayStrategy.replication_group_message_id_based(ReplicationGroupMessageId.of(rgmid))
persistent_receiver: PersistentMessageReceiver = messaging_service.create_persistent_message_receiver_builder()\
            .with_message_auto_acknowledgement()\
            .with_message_replay(reply_strategy)\
            .build(durable_exclusive_queue)
persistent_receiver.start()

Using CCSMP for Replay from Message ID

const string &replayMsgId = "rmid1:0117b-75462900ca8-00000000-00135082";
flowProps[propIndex++] = strdup(SOLCLIENT_FLOW_PROP_REPLAY_START_LOCATION);
flowProps[propIndex++] = strdup(replayMsgId.c_str());
csmpRc = solClient_session_createFlow(
                        (char **)flowProps,
                         session_mp,
                        &opaqueFlow_p,
                        &flowFuncInfo,
                        sizeof(flowFuncInfo));

Using JCSMP for Replay from Message ID:

String replayMsgId = "rmid1:0117b-75462900ca8-00000000-00135082";  
ReplayStartLocation loc = JCSMPFactory.onlyInstance().createReplicationGroupMessageId(replayMsgId);
consFlowProps.setReplayStartLocation(loc);
consumer = _jSession.createFlow(myConsumer, consFlowProps, null, myConsumer);

Using NodeJS/JavaScript for Replay from Message ID

var replayMsgId = "rmid1:0117b-75462900ca8-00000000-00135082";
messageConsumerProperties.replayStartLocation = solace.SolclientFactory.createReplicationGroupMessageId(replayMsgId);
consumer = this.m_session.createMessageConsumer(messageConsumerProperties);

Using .NET for Replay from Message ID

Note: One important thing about .NET is the ReplayStartLocation property in FlowProperties has been deprecated so it needs to use ReplayStartLocationEx (All the other replay start locations should use it as well in the future)

FlowProperties fp = new FlowProperties();
String replayMsgId = "rmid1:0117b-75462900ca8-00000000-00135082";
IReplicationGroupMessageId rpStart = ContextFactory.Instance.CreateReplicationGroupMessageId(replayMsgId);
fp.ReplayStartLocationEx = rpStart;
flowHandle = m_session.CreateFlow(fp, bindEndpoint, topicSubscription, this._HandleMessageEvent, this._HandleFlowEvent, epProps);

Using JavaRTO for Replay from Message ID:

Map<String, String> flowPropsMap = new HashMap<String, String>(_flowProperties);
String replayMsgId = "rmid1:0117b-75462900ca8-00000000-00135082";
flowPropsMap.put(FlowHandle.PROPERTIES.REPLAY_START_LOCATION, replayMsgId );
EventsAdapter myConsumer = new EventsAdapter(this, queue, flowProps, null, null, transactedSession, wantMsgPriorityOrderChecking);

Hope this thread comes in handy for folks trying to use this feature in the future :)
Go ahead and give it a like if it does and we'll continue to try to share content like this for future features.

Tagged:

Comments

  • manzarul
    manzarul Member Posts: 20 ✭✭

    Hi ,
    I was trying to find replayMsgId in message header using spring cloud stream , i printed all header which i received but not able to find any values as "rmid1:0117b-75462900ca8-00000000-00135082"

    Headers which i got as below:

    1. solace_senderTimestamp --1628606024803
    2. solace_expiration -- 0
    3. deliveryAttempt -- 1
    4. solace_destination -- test/msg/replay
    5. solace_timeToLive -- 0
    6. solace_receiveTimestamp --0
    7. skip-input-type-conversion -- false
    8. solace_discardIndication -- false
    9. solace_priority ---1
    10. solace_redelivered --false
    11. id --1cbf2434-fb03-d17f-9174-1e3a2f0d6edf // this id is not accepted for message replay.
    12. contentType --application/json
    13. solace_senderId --Try-Me-Pub/solclientjs/chrome-91.0.4472-Windows-0.0.0/2758948243/0003
    14. timestamp --1628606684861

    Need your help here to know how to get ReplicationGroupMessageId in spring cloud Stream project.

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Thanks for the heads up @manzarul. Just linking to the other post incase others come across this: https://solace.community/discussion/918/how-to-get-replicationgroupmessageid-for-message-replay-with-spring-cloud-stream#latest

  • Tamimi
    Tamimi Member, Administrator, Employee Posts: 491 admin

    You can also do replay by message id using python as follows:

      rgmid = "rmid1:096b4-e39eaab3209-00000000-0000002d"
      reply_strategy = ReplayStrategy.replication_group_message_id_based(ReplicationGroupMessageId.of(rgmid))
      persistent_receiver: PersistentMessageReceiver = messaging_service.create_persistent_message_receiver_builder()\
                .with_message_auto_acknowledgement()\
                .with_message_replay(reply_strategy)\
                .build(durable_exclusive_queue)
      persistent_receiver.start()
    
  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Thanks @Tamimi - I added Python to the main post!

  • SeanTYH
    SeanTYH Member Posts: 12 ✭✭

    @marc Hello! Can I ask, if my application code is using the above:

    JCSMPFactory.onlyInstance().createReplicationGroupMessageId(replayMsgId);

    Is there any message format or GroupMessageId I can use for this to imitate the ReplayFromBeginning() function?

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 914 admin

    Hi @SeanTYH , 
    
    Unless I'm misunderstanding I think you want the following: 
    
    JCSMPFactory.onlyInstance().createReplayStartLocationBeginning();
    

    Does that give you what you need?

  • SeanTYH
    SeanTYH Member Posts: 12 ✭✭
    edited September 2023 #8

    I m sort of looking to (if required) replay from beginning on occasion, but if possible replay a subset of messages using the group message id. So i was wondering if the group message id has any sort of pattern that imitates replaying from beginning of the replay log, that if required, I can just change to a group message id that represents a message.