What is Duplicate Durable Subsciption in JMS - java

I am struggling to understand Durable subscription. I understand that when a Listener registers itself as a Durable Subscriber to a Topic, it tells JMS - "Hey, I am durable subscriber, from now onwards you need to store all the messages in Topic if I am not there and pass me those messages when I come back"
Now, if that's the case, why can't two subscribers ask for this durable subscription?
Am I missing something?

Quoting from the Java EE tutorial
A durable subscriber registers a durable subscription by specifying a
unique identity that is retained by the JMS provider. Subsequent
subscriber objects that have the same identity resume the subscription
in the state in which it was left by the preceding subscriber. If a
durable subscription has no active subscriber, the JMS provider
retains the subscription’s messages until they are received by the
subscription or until they expire.
To make durable subscriptions work for multiple subscribers on 1 durable subscription the broker would have to store each individual message from the creation of the topic (by the first-ever subscriber) until its expiry, ie potentially forever if no message TTL is specified, because at any point in time a new subscriber can pop in and claim all the messages it "missed" (that is, all messages since the subscription was created). That's just not feasible.
I may be missing the point here, but I can't see how having multiple simultaneous subscribers sharing a subscription would be more practical than defining two separate subscriptions?

The understanding of Duplicate Durable Subscription is incorrect.
Durable subscription does not mean that no multiple subscribers can subscribe. It means no One subscriber can have two different identifiers for durable.

Related

Delete messages from specific durable Tibco EMS subscription

I have Tibco EMS server, some topics and number of durable subscriptions to this topics(more than one to every topic).
My task is to delete(by receiving them with appropriate acknowledge mode) messages for specific durable subscriber.
My question: is it possible to manage subscriber's pending messages by "substitute" it with my own subscriber(with the same name, id)? And it's important not to affect topic's pending messages, in other words, delete some messages from one topic subscription, but remain those messages in other topic(the same topic) subscription.
Well, I've found the answer, just forgot to post it before.
As mentioned above, under question itself, there is no way to delete messages from topic. But I had little different task: to delete messages under specific durable subscription. And this is real(with some conditions).
Lets say, you have to delete messages from durable subscription "MySubscr". To do so you should create connection and create Durable Subscriber with same name "MySubscr". But it's not enough. If you just do so, then another durable subscriber will be created with the same name, but under connection with different ClientID . And it will operate as standalone durable connection without any impact to required "MySubscr" durable(actually, they will look like MySubscr:123 and MySubscr:567 durable subscription, where 123 and 567 are the ClientIDs, at least for TibcoEMS). To fix it, you should set ClientID explicitly to your connection by connection.setClientID() method, but you can do it only if initial connection is not connected(that's why I noted about durable subscriber, it can accumulate messages without subscriber connected).
So you should wait until subscriber will disconnect by itself(isConnected() method for TibcoEMS, I didn't see similar method in JMS API, but suppose most of implementations have something like this) or to destroy connection(with certain ClientID) manually(TibjmsAdmin.destroyConnection() method from TibcoEMS). And after this set the ClientID to your connection and get access to the messages of this subscriber. You can read messages by consuming them with Acknowledge mode Client(then they will remain in the topic), or with the mode Auto(then they will be deleted).
Important note: you can't consume some certain message, all the messages are consumed like in queue, so you can do it only one-by-one. If you found some unwanted message and wish to delete it(by consuming with autoacknowledge mode or by calling acknowledge() method on the message) then you'll lost all prior messages with it. AFAIK, there is no way to delete message without deleting prior ones.
Another important note: while you doing your messages magic it is important for the initial client not to connect again till your connection isn't closed, because it will get DublicateClientIDException(if it is using certain ClientID) or it will create another Durable Subscription which will have no access to the prior messages from the subscription.

At what point in time is a message removed from a topic?

I have a topic. I have 10 consumers subscribed for it. As per my understanding, a message will be removed from
topic when all consumers have received it. Right? Once it is removed, any further subscriber
will not be notified for that specific message. I could not confirm this in the JMS specification anywhere.
A broker (in your case Active MQ) will deliver a publication to all active subscribers, both durable and non-durable (meaning consumer applications which are running when a publication was made on a topic and consuming messages and any durable subscribers which are not active). The broker will then discard the publication. If there are no active subscribers or durable subscribers for a topic, the broker will discard the publication immediately. It will not wait for any subscribers to become active. The only exception is in the case of "Retained Publication" option being exercised, where the broker will cache a publication and deliver to consumers who may arrive later. But note that broker will not wait for all consumers to receive publication before removing it from a topic. I would say there is nothing like 'removing from topic'.
Hope I am clear.
Only active subscribers will get your message in that case, after that your message is removed.
If you want to send your message also to inactive subscribers you can configure durable subscription.

Point-to-point vs publish/subscribe models in JMS

I am new to JMS. I have started with "hello world" where I am publishing the message from java application on Topic and
listening it from client (node.js Javascript). I have gone through this wikipedia entry, but I have some questions based on my previous theoretical understanding.
As per my understanding, point-to-point is the queue implementation where there can be at most one consumer subscribed on queue and can
be consumed by that only. Neither producer nor the consumer knows about each other. Queue is hosted on message brokers in my case Apache ActiveMQ. Queue can be created by producer before publishing the message (or it can be created from console in advance).
In case of publish/subscribe model, it's almost same as point-to-point except the fact we use Topic instead of queue. In this model there can be more than more consumer on the topic. Once the message is published, all the subscribers will be notified. Now if any of the subscriber, send the acknowledgment for the published message, message will taken as consumed and it will no longer be available for new subscriber?
Point to Point means message(s) is sent from one application(producer or sender) to another application(consumer/receiver) via a queue. There can be more than one consumer listening on a queue but only one of them will be get the message. Hence it is Point to Point or One to One.
On the other hand Publish/Subscribe is another messaging model where a message(or publication as it is commonly called) is sent to multiple consumers(or subscribers) through a topic. The topic is the link between publisher and subscriber. The subscribers may or may not acknowledge the published message. Implementations like JMS acknowledge the message the messaging providers but not the sender of the message. Publications will be received by all subscribers, durable and non-durable. Any new subscribers on the same topic will not get the publication unless it is a Retained publication.
I would recommend you to read further on,
Durable subscription
Non-durable subscription
Retained publication

Receiving messages from the start of a topic

So I was wondering about a problem. Consider a publisher creates a topic at 10:00 am and immediately starts publishing messages on to the topic. It notifies the consumers of creation of the topic and then they subscribe to the topic at 10:01 am. These consumers will not receive messages sent by the publishers between 10:00 am - 10:01 am. So should the messaging provider immediately discard these messages if it finds that there are no active subscribers for this topic to receive any messages. Can we provide a subscription mechanism by which consumers can specify from which point they want to receive messages, (for eg. from the start of the topic or 12/25/2011 10:00 am PST etc.)
In Publish/Subscribe messaging model, publisher does not notify creation of a topic to subscribers.
Publishers and Subscribers are loosely coupled via the topic. So a publisher will not know whether there are any subscribers or not. Messaging provider discards a publication on topic if there are no subscribers for that topic. Some messaging providers inform the publisher if there are no takers for publication. This way publisher can make a decision on whether to continue publishing or not.
Subscribers will start getting publication from the time when a subscription is created. There are two types of subscriptions, durable and non-durable. Non-durable subscriptions are the ones where publications are delivered to subscribers as long as they are active. Durable subscription is the one where publication are delivered even when the subscribers are not active.
There is concept of Retain Publication where in messaging provider retains one latest publication and delivers to subscribers who join late.

Durable Subscriber on Weblogic. How it work?

I want to understand a thing: When a durable subscriber is activated on a topic, in add on this topic there is another subscriber (mdb). Is possible that the durable subscriber take the messages and don't provide it to the MDB?
Thanks a lot..
When a message is sent to a topic, by intent there's a separation between the publisher and the consumers.
Although there are ways you can create transactional delivery around sending to all consumers, there's no way a consumer can take a message and prevent other consumers from receiving a message as well.

Categories

Resources