# Connect to RabbitMQ

Show the messages of your RabbitMQ exchanges on the timeline, and do not take a message from your services.

Source: https://www.eventcatalog.dev/tools/streamview/docs/how-to/connect-to-rabbitmq

You need the `streamview` program, Node.js, and the address of a RabbitMQ server.

streamview does not read the queues of your services. It makes a temporary queue of its own.
Thus your services continue to get all their messages.
See [How streamview reads without taking messages](https://www.eventcatalog.dev/tools/streamview/docs/explanation/how-streamview-reads#rabbitmq).

:::note
RabbitMQ does not keep old messages for a new queue. You see only the messages that come after streamview starts.
:::

## Show all exchanges

Run this command with the address, the user, and the password of your server:

```
streamview rabbitmq --url amqp://user:password@localhost:5672
```

The first time, the command installs the RabbitMQ adapter. This takes some seconds.
The browser then opens. Each routing key on each exchange is one lane.

To find the exchanges, streamview uses the management API of RabbitMQ on port 15672.
It uses the user and the password from `--url`.
It does not read the exchanges of RabbitMQ itself, which have names that start with `amq.`.

## Use a virtual host or TLS

Put the virtual host at the end of the address:

```
streamview rabbitmq --url amqp://user:password@localhost:5672/my-vhost
```

For a connection with TLS, start the address with `amqps://`:

```
streamview rabbitmq --url amqps://user:password@broker.example.com:5671
```

## Show only some exchanges

Add `--exchanges` with the names, and a comma between them:

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --exchanges orders,payments
```

## Connect if the management API is not available

If the management API has a different address, give it with `--management`:

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --management http://localhost:8080
```

If there is no management API, do these two steps:

1. Add `--no-management`.
2. Add `--exchanges` with the names of the exchanges.

For a direct exchange, also add `--routing-keys` with the routing keys that you want to see.
Without the management API, streamview cannot find them.

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --no-management \
  --exchanges orders,payments --routing-keys charge,refund
```

## See the messages that go directly to a queue

A program can send a message directly to a queue. RabbitMQ calls this the default exchange.
streamview cannot connect its queue to the default exchange, thus it does not see these messages.

To see them, use the tracer of RabbitMQ:

1. On the RabbitMQ server, run `rabbitmqctl trace_on`.
2. Start streamview with `--trace`.

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --trace
```

streamview then gets a copy of each message that a program publishes, on all exchanges.

:::caution
The tracer makes the RabbitMQ server slower. Do not keep it on in a busy production system.
To stop it, run `rabbitmqctl trace_off`.
:::

## Connect the messages of one order

If your messages are CloudEvents, streamview uses their `correlationid` field.

If your messages are plain JSON, streamview uses the `correlation_id` property of the message.
If your programs do not set this property, add `--correlation-field` with the name of the field that all messages of one order contain.

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --correlation-field orderId
```

## Decrease the number of lanes

Each routing key becomes one lane. If your routing keys contain IDs or regions, there are too many lanes.
Use `--depth` to make a lane from only the first parts of the routing key.

```
streamview rabbitmq --url amqp://user:password@localhost:5672 --depth 2
```

With `--depth 2`, `order.created.eu` and `order.created.us` are one lane.

## Related

- [Command line: `streamview rabbitmq`](https://www.eventcatalog.dev/tools/streamview/docs/reference/command-line#streamview-rabbitmq)
- [Watch a RabbitMQ system](https://www.eventcatalog.dev/tools/streamview/docs/tutorials/watch-a-rabbitmq-system)
- [Event format: events from RabbitMQ messages](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#events-from-rabbitmq-messages)
