我已按照找到here的说明尝试使用JMSAppender。我正在尝试使用ActiveMQ在MuleStudio环境中使用它。
我在log4j.xml文件中添加了以下内容:
<appender name="jms" class="org.apache.log4j.net.JMSAppender">
<param name="InitialContextFactoryName" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory" />
<param name="ProviderURL" value="tcp://localhost:61616" />
<param name="TopicBindingName" value="logTopic" />
<param name="TopicConnectionFactoryBindingName" value="ConnectionFactory" />
</appender>
<logger name="org.apache.activemq">
<appender-ref ref="console" />
</logger>
我在类路径中创建了一个jndi.properties文件,其中包含以下内容:
topic.logTopic=logTopic
我将activemq-core-5.7.0.jar添加到MuleStudio的类路径中。
当我尝试运行Mule应用程序时,我得到下面的异常显示无法找到主题名称。
我使用ActiveMQ的控制台手动创建主题,但这并未改变任何内容。
我做错了什么?
控制台日志输出:
log4j: Class name: [org.apache.log4j.net.JMSAppender]
log4j: Setting property [initialContextFactoryName] to [org.apache.activemq.jndi.ActiveMQInitialContextFactory].
log4j: Setting property [providerURL] to [tcp://localhost:61616].
log4j: Setting property [topicBindingName] to [logTopic].
log4j: Setting property [topicConnectionFactoryBindingName] to [ConnectionFactory].
log4j: Getting initial context.
log4j: Looking up [ConnectionFactory]
log4j: About to create TopicConnection.
log4j: Creating TopicSession, non-transactional, in AUTO_ACKNOWLEDGE mode.
log4j: Looking up topic name [logTopic].
log4j:ERROR Could not find name [logTopic].
log4j:ERROR Error while activating options for appender named [jms].
javax.naming.NameNotFoundException: logTopic
at org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:235)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.apache.log4j.net.JMSAppender.lookup(JMSAppender.java:245)
at org.apache.log4j.net.JMSAppender.activateOptions(JMSAppender.java:222)
at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307)
at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:295)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:176)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:191)
at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:523)
at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:492)
at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:1001)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:867)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:773)
at org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:483)
at org.apache.log4j.LogManager.<clinit>(LogManager.java:127)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
at org.mule.module.logging.LoggerReferenceHandler.<init>(LoggerReferenceHandler.java:28)
at org.mule.module.logging.MuleLogFactory.<init>(MuleLogFactory.java:41)
at org.apache.commons.logging.LogFactory.<clinit>(LogFactory.java:32)
at org.mule.module.launcher.CompositeDeploymentListener.<init>(CompositeDeploymentListener.java:24)
at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:108)
答案 0 :(得分:0)
需要执行以下操作:
jndi.properties
目录中创建mule/conf
个文件topic.logTopic=logTopic
mule/lib/boot
:activemq-client-5.8.0.jar
,
geronimo-j2ee-management_1.1_spec-1.0.1.jar
,geronimo-jms_1.1_spec-1.1.1.jar
log4j.properties
# settings for specific packages log4j.logger.org.mule=INFO log4j.logger.com.mule.support=INFO #log4j.logger.org.mule.api.processor.LoggerMessageProcessor=${custom-level} log4j.logger.httpclient.wire.header=DEBUG, jms log4j.logger.org.apache.activemq=INFO, stdout ## Configure 'jms' appender. You'll also need jndi.properties file in order to make it work log4j.appender.jms=org.apache.log4j.net.JMSAppender log4j.appender.jms.InitialContextFactoryName=org.apache.activemq.jndi.ActiveMQInitialContextFactory log4j.appender.jms.ProviderURL=tcp://localhost:61616 log4j.appender.jms.TopicBindingName=logTopic log4j.appender.jms.TopicConnectionFactoryBindingName=ConnectionFactory