I am newbie to JMS and trying my hands on it using ActiveMQ.
I want to know if there is any mechanism using which we can avoid publishing duplicate message to Topic(if same message is already present in that topic)? Or is there any way to just check & not consume ,what all messages are present in destination programatically?
It is kinda common knowledge (okay, maybe it is not that common... ) that the application is responsible for de-duplication of messages. Even for durable subscribers, the level of service of "guaranteed delivery", only "guarantees" that you will get the messages. It does not guarantee that you will get each message only once... so, even if there is a mechanism to prevent the publisher from sending the same message twice, the subscriber can still get the same message twice.
To elaborate more, I don't think that ActiveMQ has any mechanism for this. And since you can't tell if you accidentally publish the same message twice, you can't use the message sequence numbers to de-duplicate the message -- as your subscribers will get the same message with two different sequence numbers. You need to put some kind of marker in your messages, and it will be the responsibility of your subscribers to de-duplicate them.