Back to Zipkin

collector-rabbitmq

zipkin-collector/rabbitmq/README.md

3.6.13.5 KB
Original Source

collector-rabbitmq

RabbitMQCollector

This collector consumes a RabbitMQ queue for messages that contain a list of spans. Its only dependencies besides Zipkin core are the slf4j-api and the RabbitMQ Java Client.

Configuration

The following configuration can be set for the RabbitMQ Collector.

PropertyEnvironment VariableDescription
zipkin.collector.rabbitmq.concurrencyRABBIT_CONCURRENCYNumber of concurrent consumers. Defaults to 1
zipkin.collector.rabbitmq.connection-timeoutRABBIT_CONNECTION_TIMEOUTMilliseconds to wait establishing a connection. Defaults to 60000 (1 minute)
zipkin.collector.rabbitmq.queueRABBIT_QUEUEQueue from which to collect span messages. Defaults to zipkin
zipkin.collector.rabbitmq.uriRABBIT_URIRabbitMQ URI spec-compliant URI, ex. amqp://user:pass@host:10000/vhost

If the URI is set, the following properties will be ignored.

PropertyEnvironment VariableDescription
zipkin.collector.rabbitmq.addressesRABBIT_ADDRESSESComma-separated list of RabbitMQ addresses, ex. localhost:5672,localhost:5673
zipkin.collector.rabbitmq.passwordRABBIT_PASSWORDPassword to use when connecting to RabbitMQ. Defaults to guest
zipkin.collector.rabbitmq.usernameRABBIT_USERUsername to use when connecting to RabbitMQ. Defaults to guest
zipkin.collector.rabbitmq.virtual-hostRABBIT_VIRTUAL_HOSTRabbitMQ virtual host to use. Defaults to /
zipkin.collector.rabbitmq.use-sslRABBIT_USE_SSLSet to true to use SSL when connecting to RabbitMQ

Caveats

The configured queue will be idempotently declared as a durable queue.

This collector uses one connection to RabbitMQ, with the configured concurrency number of threads each using one channel to consume messages.

Consumption is done with autoAck on, so messages that fail to process successfully are not retried.

Encoding spans into RabbitMQ messages

The message's body should be the bytes of an encoded list of spans.

JSON

A list of Spans in JSON. The first character must be '[' (decimal 91).

SpanBytesEncoder.JSON_V2.encodeList(spans) performs the correct JSON encoding.

Local testing

The following assumes you are running an instance of RabbitMQ locally on the default port (5672). You can download and install RabbitMQ following instructions available here. With the RabbitMQ Management CLI you can easily publish one-off spans to RabbitMQ to be collected by this collector.

  1. Start RabbitMQ server
  2. Start Zipkin server
bash
$ RABBIT_ADDRESSES=localhost java -jar zipkin.jar
  1. Save an array of spans to a file like sample-spans.json
json
[{"traceId":"9032b04972e475c5","id":"9032b04972e475c5","kind":"SERVER","name":"get","timestamp":1505990621526000,"duration":612898,"localEndpoint":{"serviceName":"brave-webmvc-example","ipv4":"192.168.1.113"},"remoteEndpoint":{"serviceName":"","ipv4":"127.0.0.1","port":60149},"tags":{"error":"500 Internal Server Error","http.path":"/a"}}]
  1. Publish them using the CLI

If you have an AMQP package like rabbitmq-c-utils or simple-amqp-client:

bash
$ amqp-publish -r zipkin < sample-spans.json

Or, if your rabbitmq host is running management extensions:

bash
$ rabbitmqadmin publish exchange=amq.default routing_key=zipkin < sample-spans.json