Ashish Agarwal
Ashish Agarwal

Reputation: 3156

Receiving message synchronically when I use multiple consumer

I am new in Active MQ. There was single consumer for my queue. I was reading message synchronically and unique string is in last of every message. Some messages was large so consumer receive those message in two part and through unique string, consumer make complete message.

StringBuilder snapshotUpdateString = new StringBuilder("");
while(true) {
    Message messageData = consumer.receive();
    TextMessage textMessage = (TextMessage) messageData;
    String receivedMessage=textMessage.getText();

    if (receivedMessage.contains("" + (char) PushPortContants.EOF)) {
        snapshotUpdateString.append(receivedMessage);
        String snapshot = snapshotUpdateString.substring(1, snapshotUpdateString.length() - 1);
        parseSaveSsUpdateData.parseAndSave(snapshot);
        snapshotUpdateString = new StringBuilder("");
    }
    else snapshotUpdateString.append(receivedMessage);
}

In queue, messages was increasing high so I add one more consumer. Now consumer is two. If message is large then single message is received in two part() to different consumer. How can make message to complete message.

In multiple consumer, I used listener. Can I receive message synchronically when i use multiple consumer?

Upvotes: 0

Views: 242

Answers (1)

Erik Williams
Erik Williams

Reputation: 933

You want to use Message Groups for this. This can be a bit tricky with multiple consumers, and requires a bit more coupling of the producer as it has to be able to set the appropriate headers.

In any case, the producer would need to mark the JMSXGroupId and JMSXGroupSeq to indicate messages and order for the particular group.

It would also be worth reading the link at the bottom of the page I linked above regarding selectors to help you choose the best method.

Upvotes: 2

Related Questions