我有一个SpringBoot应用程序,我正在尝试实现log4j2的JMS Appender。 该应用程序似乎找到了附加程序,但随后出现错误:
"JMS message Producer Not Available"
我已经声明了返回类型为org.apache.activemq.ActiveMQConnectionFactory
的bean,并在log4j2.xml中定义了附加程序和记录器(记录器在RollingFile和Console上工作正常)。
我不确定如何解决此问题,在Google上找不到很多。
感谢任何指针。
log4j2.xml附加程序条目
<JMS name="jmsQueue" destinationBindingName="logQueue"
factoryBindingName="com.mydomain.developer.myappname.ActiveMQ.MyQueueConnectionFactory"
factoryName="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
providerURL="tcp://localhost:61616"
userName="admin"
password="admin" >
<JsonLayout properties="true"/>
</JMS>
我的豆子:
package
com.mydomain.developer.myappname.ActiveMQ
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Component
public class MyQueueConnectionFactory{
@Bean
public ActiveMQConnectionFactory loggingConnectionFactory(){
return new
ActiveMQConnectionFactory("admin","admin","tcp://localhost:61616");
}
}
StackTrace:
2018-12-14 12:29:47,421 main ERROR An exception occurred processing Appender jmsQueue org.apache.logging.log4j.core.appender.AppenderLoggingException: Error sending to JMS Manager 'jmsQueue': JMS message producer not available
at org.apache.logging.log4j.core.appender.mom.JmsManager.send(JmsManager.java:458)
at org.apache.logging.log4j.core.appender.mom.JmsAppender.append(JmsAppender.java:269)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:464)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:448)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:431)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2170)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2125)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2108)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2007)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1866)
at org.apache.commons.logging.LogAdapter$Log4jLog.log(LogAdapter.java:241)
at org.apache.commons.logging.LogAdapter$Log4jLog.info(LogAdapter.java:205)
at org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker.postProcessAfterInitialization(PostProcessorRegistrationDelegate.java:330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:91)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:109)
at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:92)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:101)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:253)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1091)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1064)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:240)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:707)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at ms.allstar.developer.fibresendinboxmessagerequest.FibreSendInboxMessageRequestApplication.main(FibreSendInboxMessageRequestApplication.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:558)
at java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:1)
正如Log4j documentation所阐明的那样,JMS附加程序配置中的factoryBindingName
确实不是 指的是Spring bean。它是指连接工厂绑定所在的JNDI名称。
尝试使用如下配置:
<JMS name="jmsQueue"
destinationBindingName="dynamicQueues/logQueue"
factoryBindingName="ConnectionFactory"
factoryName="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
providerURL="tcp://localhost:61616"
userName="admin"
password="admin">
<JsonLayout properties="true"/>
</JMS>
要清楚,ActiveMQ InitialContextFactory
实现仅在客户端,这意味着它实际上并没有通过网络连接来“查找”远程服务器上的资源。相反,通常在InitialContext
的“环境”属性中配置所有资源。但是,有一个默认的JMS连接工厂,默认情况下绑定到ConnectionFactory
,如果您不想或不能专门配置它,可以在任何队列名称上使用dynamicQueues/
前缀。为了方便和简单起见,我建议您使用这些默认资源。
答案 1 :(得分:0)
基于ActiveMQ文档(访问https://activemq.apache.org/how-do-i-use-log4j-jms-appender-with-activemq),您必须创建新文件: jndi.properties 。 然后添加一行:
queue.logQueue=myQueueToLogEvents
注意,
logQueue
是您的 log4j2.xml 文件中的名称,并且
myQueueToLogEvents
是目标队列的名称。最后,消息将发送到 myQueueToLogEvents 队列。 希望对您有所帮助。