两个步骤:参考地址:http://activemq.apache.org/interceptors.html
1、开发插件类
插件类需要实现接口org.apache.activemq.broker.BrokerPlugin
activeMQ已有的实现类,如下
继承:org.apache.activemq.broker.BrokerPluginSupport=》BrokerFilter类=》BrokerPlugin接口
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerPlugin;
public class MyPlugin implements BrokerPlugin {
public Broker installPlugin(Broker broker) throws Exception {
return new MyBroker(broker);
}
}
2、配置activeMQ
<broker xmlns="http://activemq.org/config/1.0" brokerName="localhost" dataDirectory="${activemq.base}/data">
<!-- The transport connectors ActiveMQ will listen to -->
<transportConnectors>
<transportConnector name="openwire" uri="tcp://localhost:61616" />
</transportConnectors>
<plugins>
<bean id="myPlugin" class="org.myorg.MyPlugin"/>
</plugins>
</broker>
======================
今天重新测试了一下,发现XML解析有问题,可是看activemq.xsd是OK的呀,也没有顺序才是。实现是想不出怎么做。完全按照教程上来的也解释有问题,可能是一个小细节或者包冲突导致。
但是没有时间去细化问题,只想了一个绕过去的办法——本身activemq的配置文件是基于spring来实现的。那完全可以通过spring在broker实例化之前加上plugins配置信息。
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'bean'. One of '{"http://activemq.apache.org/schema/core":authorizationPlugin, "http://activemq.apache.org/schema/core":connectionDotFilePlugin, "http://activemq.apache.org/schema/core":destinationDotFilePlugin, "http://activemq.apache.org/schema/core":discardingDLQBrokerPlugin, "http://activemq.apache.org/schema/core":forcePersistencyModeBrokerPlugin, "http://activemq.apache.org/schema/core":jaasAuthenticationPlugin, "http://activemq.apache.org/schema/core":jaasCertificateAuthenticationPlugin, "http://activemq.apache.org/schema/core":jaasDualAuthenticationPlugin, "http://activemq.apache.org/schema/core":loggingBrokerPlugin, "http://activemq.apache.org/schema/core":multicastTraceBrokerPlugin, "http://activemq.apache.org/schema/core":simpleAuthenticationPlugin, "http://activemq.apache.org/schema/core":statisticsBrokerPlugin, "http://activemq.apache.org/schema/core":timeStampingBrokerPlugin, "http://activemq.apache.org/schema/core":traceBrokerPathPlugin, "http://activemq.apache.org/schema/core":udpTraceBrokerPlugin, WC[##other:"http://activemq.apache.org/schema/core"]}' is expected.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
本文介绍如何为ActiveMQ开发自定义插件并进行配置。主要包括两步:首先,开发插件类并实现BrokerPlugin接口;其次,在ActiveMQ配置文件中添加插件配置。文章还提到使用Spring进行配置的方法及XML解析时遇到的问题。
111

被折叠的 条评论
为什么被折叠?



