activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agujral <anurag_guj...@yahoo.com>
Subject Re: statistical plugin
Date Tue, 21 Jun 2011 17:12:16 GMT
Also I want to add to my first message, sometimes I am not getting any
response from the broker  when I send message to the queue
"ActiveMQ.Statistics.Broker" my program just hangs.
I am attaching the program below :

public static void main(String[] args) throws Exception  {
 //not using sdtcommon variable since it requires lot of files to be
included crazy java 
 //String abc=SDTQueue.DESTINATION_PIXEL_QUEUE_PREFIX;
  printBrokerStats(args);

}

private static void printBrokerStats(String[] args) throws JMSException { 
 //ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("vm://localhost:61616?broker.useJmx=false");
   String host=args[0];
   if(host == null){
       System.out.println("Please specify hostname");
       System.exit(1);
    }
    String sufString = ".bluekai.com";
    int sufLen = sufString.length();
    int hostLen = host.length();
    int requiredLen = hostLen - sufLen;
    String prefixHostStr = host.substring(0,requiredLen);
    long unixTime = System.currentTimeMillis() / 1000L;
        //System.out.println(unixTime);
     prefixHostStr = prefixHostStr.replace('.','-');
 String connStr = "tcp://";
 connStr += host;
 connStr += ":61616"; 
//ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory("tcp://localhost:61616");//?broker.persistent=false&broker.useJmx=false");
ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(connStr);//?broker.persistent=false&broker.useJmx=false");
  Connection connection;
  connection = connectionFactory.createConnection();
  connection.start();
 Session  session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);

   
 //Destination replyTo = session.createQueue("ActiveMQ.Statistics.Broker");
Destination replyTo =
session.createTemporaryQueue();//"ActiveMQ.Statistics.Broker");
MessageConsumer consumer = session.createConsumer(replyTo);
String queueName = "ActiveMQ.Statistics.Broker";
Destination testQueue = session.createQueue(queueName);
MessageProducer producer = session.createProducer(testQueue);
Message msg = session.createMessage();
msg.setJMSReplyTo(replyTo);
producer.send(msg);

MapMessage reply = (MapMessage) consumer.receive();

for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
  String name = e.nextElement().toString();
  if(name.equals("openwire") || name.equals("vm") ||
name.equals("tempPercentUsage") || name.equals("ssl")) continue;
  if(name.equals("brokerId") || name.equals("stomp+ssl") ||
name.equals("stomp")) continue;
  if(name.equals("dataDirectory") || name.equals("brokerName")) continue;
  String mName = "activemq."+name; 
 System.out.println(prefixHostStr+" "+mName + " " + unixTime+" "+
reply.getObject(name));
 }
//Now print per destination messages
 
  String destStr=args[1];
  String[] pids = destStr.split(",");
  //System.out.println("size="+pids.length);
  for(int i = 0; i < pids.length; i++ ) {
        Connection destConnection;
        destConnection = connectionFactory.createConnection();
        destConnection.start();
        Session  destSession = null;
        String qName = "D" + pids[i];
        destSession=destConnection.createSession(false,
destSession.AUTO_ACKNOWLEDGE);
        
        Queue destTestQueue = destSession.createQueue(qName);
        MessageProducer destProducer = destSession.createProducer(null);
        //Queue query =
destSession.createQueue("ActiveMQ.Statistics.Destination" + qName);
         
        Queue query =
destSession.createQueue("ActiveMQ.Statistics.Destination" + 
destTestQueue.getQueueName());
        Destination destReplyTo =
destSession.createTemporaryQueue();//"ActiveMQ.Statistics.Broker");
         MessageConsumer destConsumer =
destSession.createConsumer(destReplyTo);
        Message destMsg = destSession.createMessage();
        //System.out.println("q="+qName);
        destProducer.send(destTestQueue,destMsg);
        destMsg.setJMSReplyTo(destReplyTo);
        destProducer.send(query,destMsg);
        MapMessage destReply = (MapMessage) destConsumer.receive();
        //assertNotNull(destReply);
        //assertTrue(destReply.getMapNames().hasMoreElements());
       
        for (Enumeration e1 = destReply.getMapNames();e1.hasMoreElements();)
{
            String name1 = e1.nextElement().toString();
            if(name1.equals("openwire") || name1.equals("vm") ||
name1.equals("tempPercentUsage") || name1.equals("ssl")) continue;
 if(name1.equals("brokerId") || name1.equals("stomp+ssl") ||
name1.equals("stomp")) continue;
            if(name1.equals("dataDirectory") || name1.equals("brokerName"))
continue;
            String mName1 = "activemq."+destTestQueue.getQueueName()+"."+
name1; 
            System.out.println(prefixHostStr+" "+mName1 + " " + unixTime+"
"+ destReply.getObject(name1));
        }


        destConnection.close();
  }
 
 connection.close();
 }
}


--
View this message in context: http://activemq.2283324.n4.nabble.com/statistical-plugin-tp3612071p3614745.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message