JMSAppender - 无法找到主题

时间:2014-06-11 12:20:06

标签: jms activemq appender

我已按照找到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)

1 个答案:

答案 0 :(得分:0)

需要执行以下操作:

  1. jndi.properties目录中创建mule/conf个文件topic.logTopic=logTopic
  2. 将以下广告加入mule/lib/bootactivemq-client-5.8.0.jargeronimo-j2ee-management_1.1_spec-1.0.1.jargeronimo-jms_1.1_spec-1.1.1.jar
  3. 将以下内容添加到服务的log4j.properties
  4.     # 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