activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aougav <>
Subject solution how to correlate between client users and connections
Date Thu, 03 Apr 2008 08:04:27 GMT

Dear All,

To correlate between client users and actual connections we need to pass
info to the connection.
General Setup:
 1. Server is listening on topic.subject1 advisory topic to get
connection/disconnect information.
 2. Client user2 connects to broker [server] to consume topic.subject1
   2.1 Server listener gets some info. 
   2.2 We want the server to link between user2 and this particular
 3. Client stop connection
   3.1 Server listener gets some info. 
   3.2 We want the server to be sure user2 (the same (2.1)) stop consuming
messages from topic.subject1. He/she disconnect from the application.

Key point to the solution:
  We will change the connectionid, which is also the consumerid, by adding a
username/userid as the mean to link between client user and connection.

1. On the server side
          org.apache.activemq.command.ActiveMQDestination dest = 
          adminTopic = AdvisorySupport.getConsumerAdvisoryTopic(dest);
          //"listen to admin topic: "+adminTopic);
          consumer = session.createConsumer(adminTopic);

2. The client connect and MUST add his username/useridentification (some id
mean) to the connection. Example using "user2" constant:

           ActiveMQConnection topic_qconn = (ActiveMQConnection) 
           // change connectionid/consumerid before starting the connection
                  setValue("-user2-"+idgenerator.generateId()); start

Note that we must have a unique connection id for each connection, so we use
        org.apache.activemq.util.IdGenerator idgenerator = null; // added to
        if (idgenerator == null) // only once - the client init the
            idgenerator = IdGenerator();

3. The server listener is getting the advisory message
    in the
       public void onMessage(javax.jms.Message msg)
    we use (omitting try/catch etc)
       if (msg instanceof ActiveMQMessage) {
          ActiveMQMessage aMsg =  (ActiveMQMessage)msg;
          Object obj = aMsg.getDataStructure();
          if (obj instanceof ConsumerInfo) {
                // consumer to topic/queue is starting a session to it <==
                ConsumerInfo info = (ConsumerInfo) obj;
                ConsumerId cid = info.getConsumerId();
                // ... here we get cid = "-user2-ID:...uniquegeneratedid..."
                .... keep/save info...
          } else if (obj instanceof RemoveInfo) {
                // Removes a consumer, producer, session or connection.
                RemoveInfo info = (RemoveInfo) obj;
                if (info.getObjectId() instanceof ConsumerId) {
                  // consumer of topic/queue is disconnect from topic/queue 
<== disconnect
                  ConsumerId cid = (ConsumerId) info.getObjectId();
                  // ... here we get cid =
                  .... process user2 disconnect from "application"...

Best regards
View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message