0

I've created a simple Java Project. I'm trying to centralise logging with Logstash and RabbitMQ. But first I need to centralise my logs using RabbitMQ with AmqpAppender. But it doesn't work

My configurations:

  • Pom dependencies:

     <dependency>
          <groupId>org.springframework.amqp</groupId>
          <artifactId>spring-rabbit</artifactId>
          <version>1.0.0.RELEASE</version>
     </dependency>
    
  • Log4J.xml properties

    <appender name="amqp" class="org.springframework.amqp.rabbit.log4j.AmqpAppender">
        <param name="ExchangeName" value="amq.rabbitmq.log" />
        <param name="ExchangeType" value="topic" />
        <param name="RoutingKeyPattern" value="logstash" />
        <param name="ApplicationId" value="logstash" />
        <layout class="org.apache.log4j.PatternLayout">
           <param name="ConversionPattern" value="%d{ISO8601} %-5p %m%n" />
        </layout>
    </appender>
    
    <root>
      <level value="INFO" />
      <appender-ref ref="amqp" />
      <appender-ref ref="default.file" />
    </root>
    

My rabbitmq config:

I have an Exchange: amq.rabbitmq.log with a Binding to a queue: 'LOG' with routing key: logstash

But when I try to log something, the AMQP appender is not working. My RollingFileAppender is working fine with this config:

 <appender name="amqp" class="org.springframework.amqp.rabbit.log4j.AmqpAppender">
    <param name="ExchangeName" value="test.logs" />
    <param name="ExchangeType" value="topic" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{ISO8601} %-5p %m%n" />
    </layout>
</appender>

EDIT:

Some images:

Exchange: test.logs

I'm using the 'test.logs' exchange

Queue binding: LOG queue

Michaël Kees
  • 23
  • 1
  • 1
  • 6

1 Answers1

0

"NOT WORKING" is not much help - have you tried enabling debug logging for org.springframework.amqp?

Have you bound a queue to amq.rabbitmq.log?

What routing key?

BTW, that exchange is intended for internal rabbitmq logging for retrieval, not for user logging. In fact, the admin UI doesn't even have a "publish message" dialog on the exchange so I suspect you can't publish to it from an external source.

I just bound a queue to it and see messages like:

accepting AMQP connection <0.7744.183> (127.0.0.1:65004 -> 127.0.0.1:5672)

(i.e. broker logs).

Create your own exchange and bind a queue to it.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • I've changed the exchange and the queue (check links/images). Still nothing happens – Michaël Kees Apr 13 '16 at 13:28
  • Since `test.logs` is a `topic` exchange, you need to bind with a routing key (`#` for all messages, or `logstash` from your configuration); or change the exchange type to `fanout`, which needs no routing key. See the rabbitmq tutorials to understand the exchange types and the routing key needs. – Gary Russell Apr 13 '16 at 14:34