activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Santillan <donzym...@gmail.com>
Subject Re: StatisticsBrokerPlugin activation
Date Thu, 16 Sep 2010 08:33:15 GMT
As a follow up, I used this unit test which made me think that 
StatisticsBrokerPlugin is not activated:

[removed package and import lines]

public class MonitoringTest extends TestCase {
   
    private String brokerURI = "vm://testBroker?broker.persistent=false";
    private boolean transacted = false;
    private int ackMode = Session.AUTO_ACKNOWLEDGE;
   
    private Connection connection;
    private Session session;

    @Before
    public void setUp() throws Exception {
        initConnection();
        initSession();
    }
   
    @After
    public void tearDown() throws Exception {
        try {
            if (session != null) {
                session.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (Throwable ignore) {
            fail(ignore.getMessage());
        }
    }
   
    public void testBrokerMonitoring() {
        String queueName = "ActiveMQ.Statistics.Broker";
        Queue replyTo = null;
        MessageConsumer consumer = null;
        MessageProducer producer = null;
        Queue testQueue = null;
        Message msg = null;
        MapMessage reply = null;

        try {
            replyTo = session.createTemporaryQueue();
            consumer = session.createConsumer(replyTo);
           
            testQueue = session.createQueue(queueName);           
            producer = session.createProducer(testQueue);
           
            msg = session.createMessage();
            msg.setJMSReplyTo(replyTo);
            producer.send(msg);
           
            reply = (MapMessage) consumer.receive(2000);
            assertNotNull(reply);

            for (Enumeration<?> e = 
reply.getMapNames();e.hasMoreElements();) {
              String name = e.nextElement().toString();
              System.out.println(name + "=" + reply.getObject(name));
            }
        } catch (JMSException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    private void initSession() throws JMSException {
        session = connection.createSession(transacted, ackMode);
    }

    private void initConnection() throws JMSException {
        ActiveMQConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory(brokerURI);
        connection = connectionFactory.createConnection();
        connection.start();
    }
   
}

This test should list statictics coming from the broker. The test is 
failing on the line, assertNotNull(reply);, since the reply is null.

-don

Don Santillan wrote:
> Hello,
>
> I am using activemq as a dependency in a web app. My web app is 
> deployed to a jetty server which is run through maven by issuing "mvn 
> jetty:run".
>
> Of course, one part of the web app is to create and start a broker. I 
> am doing this through ActiveMQConnectionFactory (as described at the 
> last part of 
> http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html, 
> titled "Using ActiveMQConnectionFactory"):
>
> String brokerURI = "vm://testBroker?broker.persistent=false";
> ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURI);
> Connection connection = cf.createConnection();
> connection.start();
>
> Now, since I am running my web web app through maven, and activemq is 
> used as a library (not as a standalone app), I don't have an 
> activemq.xml configuration file. So, I don't know where to 
> activate/enable StatisticsBrokerPlugin as described at 
> http://activemq.apache.org/statisticsplugin.html:
>
> <broker ...>
>   <plugins>
>     statisticsBrokerPlugin/>
>   </plugins>
> </broker>
>
> Also, since I am using ActiveMQConnectionFactory to create and start 
> the broker, I can't take advantage of setting the plugin through 
> BrokerService:
>
> BrokerPlugin plugin = new StatisticsBrokerPlugin();
> BrokerPlugin[] plugins = {plugin};
>
> BrokerService broker = new BrokerService();
> try {
>   broker.addConnector(brokerURI);
>   broker.setPlugins(plugins);
>   broker.start();
> } catch (Exception e) {
>   e.printStackTrace();
> }
>
> Now, my questions are:
> 1. How will I be able to set the StatisticsBrokerPlugin with the above 
> scenario?
> 2. Is there a way to get a reference to the broker to be able to set 
> the plugin?
> 3. Is there a way to add and use activemq.xml if it is used as a 
> library and run through maven? Set in pom.xml?
>
> Please help. I really need this to work.
>
> Thanks in advance.
>
> -don

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message