I'm trying to find a way to find the number of active subscribers there are on a destination. By "active", I mean:
- If connected by polling, there's been a recent poll
- If connected by long polling (with wait-interval-millis set to a positive value), the most recent wait poll succeeded
Right now, each time a new client connects, a new subscription is added, and if they exit gracefully, the subscription is removed. However if the client disconnects abnormally, the subscription stays around until the BlazeDS server is restarted. See below for the code I'm using to list the subscriptions.
I've tried a few ways to clean these up automatically such as:
1. Including a call to channelSet.disconnectAll( ) in the logout procedure and via an ExternalInterface function in the onUnLoad event on the HTML body tag. This works in some situations but not all, such as if the browser is low on resources, if it crashes, or network disconnects.
2. Setting setSubscriptionTimeoutMinutes on the destination's NetworkSettings when it's created. This works well, EXCEPT if there are messages arriving on the server that are bound for the client. Even if the client is long gone, these messages arriving and being queued for delivery are enough to keep that timeout alive even though they don't actually get through because the client is gone.
3. Setting wait-interval-millis to a positive number (e.g. 20000) on the long-polling channel. I thought this would cause BlazeDS to kick the client and remove the subscription after the duration is up with no re-poll, but it seems not.
At this stage, I'm about to resort to a timer on the client pushing a heartbeat, but before I do that, I thought I'd throw the question out here. In the interest of full disclosure, I'm running BlazeDS 184.108.40.20678 with the turnkey Tomcat behind Apache with mod_jk.
Here's how I'm currently querying the number of "active" subscribers - this is the result I'm hoping to get to decrement after a timeout period if the client has gone away.
public String getsub(String id)
String returnval = "";
MessageBroker broker = MessageBroker.getMessageBroker(null);
MessageService service = (MessageService) broker.getService("message-service");
AsyncMessage msg = new AsyncMessage();
String clientID = UUIDUtils.createUUID(false);
Set subscribers = service.getSubscriberIds(msg, true);
Any ideas? I'm open to changes in configuration, destination creation or the above active subscriber count code!
Europe, Middle East and Africa