ActiveMQ:如何以编程方式监视嵌入式代理 [英] ActiveMQ: how to programmatically monitor embedded broker

查看:78
本文介绍了ActiveMQ:如何以编程方式监视嵌入式代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从代码内部监视嵌入式ActiveMQ 5.8代理。

I want to monitor an embedded ActiveMQ 5.8 broker from inside the code.


  • 这怎么办?

  • 我需要JMX连接吗?我想防止暴露JMX

  • 是否可以访问 org.apache.activemq.broker.jmx 没有JMX的Bean? li>
  • 经纪人本身可以连接钩子,侦听器,事件...吗?

  • 如果这是一个非常糟糕的主意,为什么?

  • How can this be done?
  • Do I need a JMX connection? I want to prevent exposing JMX
  • Is there a way of accessing org.apache.activemq.broker.jmx Beans without JMX?
  • Are there Hooks, Listeners, Events, ... that can be attached to the broker itself?
  • If this is a really bad idea, why?

推荐答案

您可以从具有嵌入式代理的流程中访问所有标准JMX MBean。而无需创建将其暴露于外界的JMX连接器。首先,您需要告诉嵌入式代理启用JMX,但不创建连接器。

You can access all the standard JMX MBeans from within the process that has an embedded broker without creating the JMX connector that would expose them to the outside world. First you need to tell the embedded broker to enable JMX but not create the connector.

    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setSchedulerSupport(true);
    brokerService.setPopulateJMSXUserID(true);
    brokerService.setSchedulerSupport(true);
    brokerService.getManagementContext().setCreateConnector(false);

然后在您的代码中,您可以像平常一样访问JMS MBean,以获取BrokerViewMBean:

Then in your code you can access the JMS MBeans as normal for instance to get the BrokerViewMBean:

protected BrokerViewMBean getProxyToBroker() throws MalformedObjectNameException, JMSException {
    ObjectName brokerViewMBean = new ObjectName(
        "org.apache.activemq:type=Broker,brokerName=localhost");
    BrokerViewMBean proxy = (BrokerViewMBean) brokerService.getManagementContext()
            .newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
    return proxy;
}

或获取QueueViewMBean:

Or to get a QueueViewMBean:

protected QueueViewMBean getProxyToQueue(String name) throws MalformedObjectNameException, JMSException {
    ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName="+name);
    QueueViewMBean proxy = (QueueViewMBean) brokerService.getManagementContext()
            .newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
    return proxy;
}

以及类似的TopicViewMBean。

And similarly a TopicViewMBean.

protected TopicViewMBean getProxyToTopic(String name) throws MalformedObjectNameException, JMSException {
    ObjectName topicViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Topic,destinationName="+name);
    TopicViewMBean proxy = (TopicViewMBean) brokerService.getManagementContext()
            .newProxyInstance(topicViewMBeanName, TopicViewMBean.class, true);
    return proxy;
}

这篇关于ActiveMQ:如何以编程方式监视嵌入式代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆