Announcement Announcement Module
Collapse
No announcement yet.
AmqpAppender get's stuck in a in infinite loop creating CachingConnectionFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AmqpAppender get's stuck in a in infinite loop creating CachingConnectionFactory

    Hi, I'm just putting together a quick proof of concept for AmqpAppender logging to RabbitMQ. So far I have a maven project with a single JUnit test and a log4j.xml file.

    Here are my dependencies

    Code:
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.amqp</groupId>
    			<artifactId>spring-rabbit</artifactId>
    			<version>1.1.4.RELEASE</version>
    		</dependency>
    		<dependency>
    			<groupId>junit</groupId>
    			<artifactId>junit</artifactId>
    			<version>4.10</version>
    			<scope>test</scope>
    		</dependency>
    		<!-- Logging Dependencies -->
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-api</artifactId>
    			<version>1.6.4</version>
    		</dependency>
    		<dependency>
    			<groupId>org.slf4j</groupId>
    			<artifactId>slf4j-log4j12</artifactId>
    			<version>1.6.4</version>
    		</dependency>
    		<dependency>
    			<groupId>log4j</groupId>
    			<artifactId>log4j</artifactId>
    			<version>1.2.16</version>
    		</dependency>
    	</dependencies>
    Here is my log4j.xml

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    
    <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    	<appender name="console" class="org.apache.log4j.ConsoleAppender">
    		<param name="Target" value="System.out" />
    		<layout class="org.apache.log4j.PatternLayout">
    			<param name="ConversionPattern" value="%-5p %c{1} - %m%n" />
    		</layout>
    	</appender>
        
    	<appender name="amqp" class="org.springframework.amqp.rabbit.log4j.AmqpAppender">
    	        <param name="host" value="idv-dev-jav02" />
    		<param name="port" value="5672" />
    		<param name="virtualHost" value="platform" />
    		<param name="username" value="username" />
    		<param name="password" value="password" />
                    <param name="ExchangeName" value="errors" />
                    <param name="RoutingKeyPattern" value="log4j.errors" />
                    <param name="ApplicationId" value="test-rabbitmq-logging" />
            </appender>
        
    	<root>
    		<priority value="debug" />
    		<appender-ref ref="console" />
    		<appender-ref ref="amqp" />
    	</root>
    	
    </log4j:configuration>
    Code:
    public class TestLoggingRabbitMQ {
    
    	private final Logger logger = LoggerFactory.getLogger(getClass());
    	
    	@Test
    	public void testMessageIsSentToRabbitMQ() throws Exception {
    		logger.debug("Hello World");
    	}
    }
    Above is my Appender configuration this seems to inject the right values, although they are never used as it never seems to go to line 446 but you can see the values are correct. I debug on line 445 (AmqpAppender.append(LoggingEvent event)) and it will just keep printing the same statements in the console and stopping on line 445 again and again.

    DEBUG CachingConnectionFactory - Using hostname [W5093711] for hostname.

    This appears and then throws a StackOverflowError eventually

    Code:
    java.lang.StackOverflowError
    	at org.apache.commons.logging.LogFactory.directGetContextClassLoader(LogFactory.java:892)
    	at org.apache.commons.logging.LogFactory$1.run(LogFactory.java:862)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.apache.commons.logging.LogFactory.getContextClassLoaderInternal(LogFactory.java:859)
    	at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:423)
    	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    	at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.<init>(AbstractConnectionFactory.java:37)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:87)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:111)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:76)
    	at org.springframework.amqp.rabbit.log4j.AmqpAppender.append(AmqpAppender.java:445)
    	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    	at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    	at org.apache.log4j.Category.callAppenders(Category.java:206)
    	at org.apache.log4j.Category.forcedLog(Category.java:391)
    	at org.apache.log4j.Category.log(Category.java:856)
    	at org.apache.commons.logging.impl.Log4JLogger.debug(Log4JLogger.java:177)
    	at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.getDefaultHostName(AbstractConnectionFactory.java:172)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:89)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:111)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:76)
    	at org.springframework.amqp.rabbit.log4j.AmqpAppender.append(AmqpAppender.java:445)
    	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    	at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    	at org.apache.log4j.Category.callAppenders(Category.java:206)
    	at org.apache.log4j.Category.forcedLog(Category.java:391)
    	at org.apache.log4j.Category.log(Category.java:856)
    	at org.apache.commons.logging.impl.Log4JLogger.debug(Log4JLogger.java:177)
    	at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.getDefaultHostName(AbstractConnectionFactory.java:172)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:89)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:111)
    	at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.<init>(CachingConnectionFactory.java:76)
    	at org.springframework.amqp.rabbit.log4j.AmqpAppender.append(AmqpAppender.java:445)
    This is the stack trace above, it repeats itself indefinitely.

    Any ideas on what I'm doing wrong as this code seems almost trivial.

  • #2
    This is a bug; please open a JIRA issue.

    The problem is you are configuring the root logger to use the amqp appender, which means that the spring-amqp classes themselves use the same appender; causing this infinite loop during initialization.

    Right now, you can't use the amqp appender to log (at least some) spring-amqp classes.

    Comment


    • #3
      As a work-around, try adding an 'error' level logger for the connection package...

      Code:
      	<logger name="org.springframework.amqp.rabbit.connection">
      		<level value="error" />
      	</logger>

      Comment

      Working...
      X