将类属性暴露给JMX for Mule自定义路由器:我有哪些选择? [英] Exposing class attributes to JMX for Mule custom router: what are my options?

查看:228
本文介绍了将类属性暴露给JMX for Mule自定义路由器:我有哪些选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Mule Enterprise Standalone 3.1.2我正在通过子类检测org.mule.routing.UntilSuccessful的属性.我的子类用作自定义路由器.

Using Mule Enterprise Standalone 3.1.2 I'm instrumenting attributes of the org.mule.routing.UntilSuccessful via a subclass. My subclass is used as a custom router.

<flow name="Queue Handler" processingStrategy="synchronous">
    <inbound-endpoint ref="Some.Queue">
        <vm:transaction action="ALWAYS_BEGIN"/>
    </inbound-endpoint>

    <custom-router class="com.company.product.mule.UntilSuccessfulSubclass">
        <flow-ref name="SomeFlow" />

        <spring:property name="objectStore" ref="SomeObjectStore" />
        <spring:property name="maxRetries" value="${maxRetries}" />
        <spring:property name="secondsBetweenRetries" value="${secondsBetweenRetries}" />
        <spring:property name="deadLetterQueue" ref="Cancel.Queue" />
        <spring:property name="maxThreads" value="${maxThreads}" />
        <spring:property name="maxBufferSize" value="${maxBufferSize}" />
        <spring:property name="threadTTL" value="${threadTTL}" />
    </custom-router>
</flow>

目前,我正在通过@ManagedAttribute在我的直到成功子类的getter和setter上测量曝光.

Currently I'm instrumenting the exposure via @ManagedAttribute on the getters and setters of my subclass of UntilSuccessful.

看着Mule核心xsd,似乎没有选择传递Bean而不是传递类的选项.

Looking at the Mule core xsd it doesn't appear that I have the option to pass in a bean instead of a class.

我更喜欢使用 Spring的MBeanExporter功能,因为这将使我避免通过添加注释来更改类文件,而且更烦人的是,必须重写超类方法,以便我可以检测JMX暴露.

I'd prefer to use Spring's MBeanExporter functionality because this would allow me to avoid changing my class file by adding annotations and, more annoyingly, by having to override superclass methods just so I can instrument the JMX exposure.

推荐答案

MuleSoft没有透露有关增强请求何时/是否通过的消息.但是,MuleSoft的支持团队确实提供了一种解决方法:

No word from MuleSoft as to when/whether the enhancement request will go through. However, MuleSoft's support team did provide a workaround:

  • 创建定义要在JMX中公开的方法的接口
  • UntilSuccessfulSubclass中的实现接口
  • initialise()中包括以下方法:

  • Create interface that defines methods you want to expose in JMX
  • Implement interface in UntilSuccessfulSubclass
  • Include the following method in initialise():

private void registerMBean()
{
    final JmxSupportFactory jmxSupportFactory = AutoDiscoveryJmxSupportFactory.getInstance();
    final JmxSupport jmxSupport = jmxSupportFactory.getJmxSupport();
    final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    final String rawName = getName() + "(" + getType() + ")";
    final String name = jmxSupport.escape(rawName);
    final String jmxName = String.format("%s:%s%s", jmxSupport.getDomainName(muleContext, !muleContext.getConfiguration().isContainerMode()), "type=ODM,name=", name);
    try
    {
        final ObjectName on = jmxSupport.getObjectName(jmxName);
        final ClassloaderSwitchingMBeanWrapper mBean = new ClassloaderSwitchingMBeanWrapper(this, UntilSuccessfulMBean.class, muleContext.getExecutionClassLoader());
        logger.debug("Registering custom router with name: " + on);
        mBeanServer.registerMBean(mBean, on);
    }
    catch (final Exception e)
    {
        logger.error(e.getMessage());
    }
}

这种方法不需要对原始的Mule配置文件(在我的原始帖子中部分引用)进行任何更改.

This approach does not require any change to the original Mule config file (partially referenced in my original post).

这种方法的一个缺点是我的MBean必须出现在Mule中. JMX中的目录,而不是与该上下文之外的所有其他MBean进行分组,但这可以完成工作.我没有花点时间来研究Mule的JMX软件包,但有可能.

One downside to this approach is that my MBean has to appear in the Mule. directory in JMX instead of grouped with all of my other MBeans outside of that context, but it gets the job done. I don't have the points to spend on digging into Mule's JMX packages but it may be possible.

这篇关于将类属性暴露给JMX for Mule自定义路由器:我有哪些选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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