others - spring - SpringBoot Log4j2 JMS附加程序-> "JMS message Producer Not Available"

我有一個SpringBoot應用程序


JMS message Producer Not Available



我聲明了一個返回類型的beanorg.apache.activemq.ActiveMQConnectionFactory並在log4j2.xml中定義了appender和logger。

我不確定如何解決這個問題

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)



时间: 原作者:

由於Log4J文檔明確指出,JMS appender配置中的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文檔(訪問https://activemq.apache.org/how-do-i-use-log4j-jms-appender-with-activemq)必須創建新文件:jndi.properties,然後添加一行:


queue.logQueue=myQueueToLogEvents



注意


logQueue 



這是log4j2.xml文件的名字

 
myQueueToLogEvents



這是目標隊列的名稱,最後消息被發送到myQueueToLogEvents隊列,希望能對你幫助。

原作者:
...