WSO2 API Manager 2.1.0反复出现javax.naming.NameNotFoundException异常求助
WSO2 APIM 2.1.0 JMS事件发布器错误解决方案
问题描述
使用wso2am-2.1.0时,wso2carbon.log反复出现以下错误,导致日志文件异常膨胀:
ERROR {org.wso2.carbon.event.output.adapter.core.internal.OutputAdapterRuntime} - Event dropped at Output Adapter 'jmsEventPublisher' for tenant id '-1234', Cannot acquire JNDI context, JMS Connection factory : TopicConnectionFactory or default destinationName : throttleData for JMS CF : jmsEventPublisher using : {transport.jms.ConcurrentPublishers=allow, java.naming.provider.url=repository/conf/jndi.properties, java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory, transport.jms.DestinationType=topic, transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory, transport.jms.Destination=throttleData} {org.wso2.carbon.event.output.adapter.core.internal.OutputAdapterRuntime} org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterRuntimeException: Cannot acquire JNDI context, JMS Connection factory : TopicConnectionFactory or default destinationName : throttleData for JMS CF : jmsEventPublisher using : {transport.jms.ConcurrentPublishers=allow, java.naming.provider.url=repository/conf/jndi.properties, java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory, transport.jms.DestinationType=topic, transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory, transport.jms.Destination=throttleData} at org.wso2.carbon.event.output.adapter.jms.internal.util.JMSConnectionFactory.<init>(JMSConnectionFactory.java:90) at org.wso2.carbon.event.output.adapter.jms.JMSEventAdapter.initPublisher(JMSEventAdapter.java:202) at org.wso2.carbon.event.output.adapter.jms.JMSEventAdapter.connect(JMSEventAdapter.java:135) at org.wso2.carbon.event.output.adapter.core.internal.OutputAdapterRuntime.publish(OutputAdapterRuntime.java:68) at org.wso2.carbon.event.output.adapter.core.internal.CarbonOutputEventAdapterService.publish(CarbonOutputEventAdapterService.java:143) at org.wso2.carbon.event.publisher.core.internal.EventPublisher.process(EventPublisher.java:425) at org.wso2.carbon.event.publisher.core.internal.EventPublisher.sendEvent(EventPublisher.java:232) at org.wso2.carbon.event.publisher.core.internal.EventPublisher.onEvent(EventPublisher.java:300) at org.wso2.carbon.event.stream.core.internal.EventJunction.sendEvents(EventJunction.java:194) at org.wso2.carbon.event.processor.core.internal.listener.SiddhiOutputStreamListener.receive(SiddhiOutputStreamListener.java:103) at org.wso2.siddhi.core.stream.output.StreamCallback.receiveEvents(StreamCallback.java:98) at org.wso2.siddhi.core.stream.output.StreamCallback.receive(StreamCallback.java:69) at org.wso2.siddhi.core.stream.StreamJunction.sendEvent(StreamJunction.java:126) at org.wso2.siddhi.core.stream.StreamJunction$Publisher.send(StreamJunction.java:323) at org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback.send(InsertIntoStreamCallback.java:46) at org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter.sendToCallBacks(OutputRateLimiter.java:78) at org.wso2.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter.process(PassThroughOutputRateLimiter.java:40) at org.wso2.siddhi.core.query.selector.QuerySelector.processNoGroupBy(QuerySelector.java:123) at org.wso2.siddhi.core.query.selector.QuerySelector.process(QuerySelector.java:86) at org.wso2.carbon.apimgt.throttling.siddhi.extension.EmitOnStateChange.process(EmitOnStateChange.java:80) at org.wso2.siddhi.core.query.processor.stream.StreamProcessor.processEventChunk(StreamProcessor.java:45) at org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor.process(AbstractStreamProcessor.java:101) at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.processAndClear(ProcessStreamReceiver.java:154) at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.process(ProcessStreamReceiver.java:80) at org.wso2.siddhi.core.query.input.ProcessStreamReceiver.receive(ProcessStreamReceiver.java:102) at org.wso2.siddhi.core.stream.StreamJunction.sendEvent(StreamJunction.java:126) at org.wso2.siddhi.core.stream.StreamJunction$Publisher.send(StreamJunction.java:323) at org.wso2.siddhi.core.query.output.callback.InsertIntoStreamCallback.send(InsertIntoStreamCallback.java:46) at org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter.sendToCallBacks(OutputRateLimiter.java:78) at org.wso2.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter.process(PassThroughOutputRateLimiter.java:40) at org.wso2.siddhi.core.query.selector.QuerySelector.processInBatchGroupBy(QuerySelector.java:253) at org.wso2.siddhi.core.query.selector.QuerySelector.process(QuerySelector.java:78) at org.wso2.carbon.apimgt.throttling.siddhi.extension.ThrottleStreamProcessor.process(ThrottleStreamProcessor.java:175) at org.wso2.siddhi.core.query.processor.stream.StreamProcessor.processEventChunk(StreamProcessor.java:45) at org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor.process(AbstractStreamProcessor.java:101) at org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor.process(EntryValveProcessor.java:47) at org.wso2.siddhi.core.util.Scheduler$EventCaller.run(Scheduler.java:171) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: javax.naming.NameNotFoundException: TopicConnectionFactory at org.wso2.andes.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:271) at javax.naming.InitialContext.lookup(InitialContext.java:411) at org.wso2.carbon.event.output.adapter.jms.internal.util.JMSUtils.lookup(JMSUtils.java:339) at org.wso2.carbon.event.output.adapter.jms.internal.util.JMSConnectionFactory.<init>(JMSConnectionFactory.java:85) ... 43 more
错误核心是JMS事件发布器jmsEventPublisher无法通过JNDI找到TopicConnectionFactory,导致节流事件无法发送,反复触发错误日志。
解决方案
1. 修复JNDI配置文件
打开<APIM安装目录>/repository/conf/jndi.properties,确保包含以下配置:
# 配置Topic连接工厂,指向内置Andes MQ connectionfactory.TopicConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:5672' # 配置节流事件对应的Topic topic.throttleData = throttleData
- 若使用外部MQ(如ActiveMQ),需替换连接字符串为对应MQ的地址和认证信息。
- 确认
java.naming.provider.url配置的路径正确,日志中显示路径为repository/conf/jndi.properties,需确保该文件存在于对应位置。
2. 验证内置Andes MQ状态
- 检查
wso2carbon.log中是否有Andes启动成功的日志,如INFO {org.wso2.andes.server.AndesServer} - Starting Andes Server。 - 若Andes未启动,可能是端口5672被占用,修改
<APIM安装目录>/repository/conf/andes/andes.xml中的端口配置,同步更新jndi.properties里的brokerlist端口后重启服务器。
3. 禁用不必要的节流事件发布器
如果业务不需要将节流事件发送到JMS Topic,可直接禁用该发布器:
- 进入
<APIM安装目录>/repository/deployment/server/eventpublishers/,找到ThrottleEventPublisher.xml,重命名为ThrottleEventPublisher.xml.disabled。 - 重启APIM服务器,错误日志将不再产生。
4. 临时调整日志级别缓解膨胀
若需临时减少日志输出,修改<APIM安装目录>/repository/conf/log4j.properties:
# 将ERROR级别改为WARN或INFO,避免打印完整错误栈 log4j.logger.org.wso2.carbon.event.output.adapter.core.internal.OutputAdapterRuntime=WARN
注意:此为临时方案,建议优先解决根本问题。
内容的提问来源于stack exchange,提问作者Lilan Mihiranga
相关产品推荐
相关产品推荐

