Skip navigation
TobySG
Currently Being Moderated

Detecting dead subscribers

Apr 5, 2010 9:56 AM

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 3.2.0.3978 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();

        msg.setDestination(id);

 

        String clientID = UUIDUtils.createUUID(false);

        msg.setClientId(clientID);

        msg.setMessageId(UUIDUtils.createUUID(false));

        Set subscribers = service.getSubscriberIds(msg, true);

 

        Integer setsize=subscribers.size();

        return setsize.toString();

  }

 

Any ideas? I'm open to changes in configuration, destination creation or the above active subscriber count code!

 

Thanks,

Toby.

 

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points