问题描述:

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

网友答案:

"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.

相关阅读:
Top