This is documentation for Rasa Open Source Documentation v2.0.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (2.6.x).

Version: 2.0.x

Event Brokers

An event broker allows you to connect your running assistant to other services that process the data coming in from conversations. For example, you could connect your live assistant to Rasa X to review and annotate conversations or forward messages to an external analytics service. The event broker publishes messages to a message streaming service, also known as a message broker, to forward Rasa Events from the Rasa server to other services.


All events are streamed to the broker as serialized dictionaries every time the tracker updates its state. An example event emitted from the default tracker looks like this:

"sender_id": "default",
"timestamp": 1528402837.617099,
"event": "bot",
"text": "what your bot said",
"data": "some data about e.g. attachments"
"metadata" {
"a key": "a value",

The event field takes the event's type_name (for more on event types, check out the events docs).

Pika Event Broker

The example implementation we're going to show you here uses Pika , the Python client library for RabbitMQ.

Adding a Pika Event Broker Using the Endpoint Configuration

You can instruct Rasa to stream all events to your Pika event broker by adding an event_broker section to your endpoints.yml:

type: pika
url: localhost
username: username
password: password
- queue-1
# you may supply more than one queue to publish to
# - queue-2
# - queue-3

Rasa will automatically start streaming events when you restart the Rasa server.

Adding a Pika Event Broker in Python

Here is how you add it using Python code:

from rasa.core.brokers.pika import PikaEventBroker
from rasa.core.tracker_store import InMemoryTrackerStore
pika_broker = PikaEventBroker('localhost',
tracker_store = InMemoryTrackerStore(domain=domain, event_broker=pika_broker)

Implementing a Pika Event Consumer

You need to have a RabbitMQ server running, as well as another application that consumes the events. This consumer to needs to implement Pika's start_consuming() method with a callback action. Here's a simple example:

import json
import pika
def _callback(self, ch, method, properties, body):
# Do something useful with your incoming message body here, e.g.
# saving it to a database
print('Received event {}'.format(json.loads(body)))
if __name__ == '__main__':
# RabbitMQ credentials with username and password
credentials = pika.PlainCredentials('username', 'password')
# Pika connection to the RabbitMQ host - typically 'rabbit' in a
# docker environment, or 'localhost' in a local environment
connection = pika.BlockingConnection(
pika.ConnectionParameters('rabbit', credentials=credentials))
# start consumption of channel
channel =

Kafka Event Broker

It is possible to use Kafka as the main broker for your events. In this example we are going to use the python-kafka library, a Kafka client written in Python.

Adding a Kafka Event Broker Using the Endpoint Configuration

You can instruct Rasa to stream all events to your Kafka event broker by adding an event_broker section to your endpoints.yml.

Using the SASL_PLAINTEXT protocol the endpoints file must have the following entries:

url: localhost
client_id: kafka-python-rasa
security_protocol: PLAINTEXT
type: kafka

If using the SSL protocol, the endpoints file should look like:

url: localhost
topic: topic
security_protocol: SSL
type: kafka

Adding a Kafka Broker in Python

The code below shows an example on how to instantiate a Kafka producer in your script.

from rasa.core.brokers.kafka import KafkaEventBroker
from rasa.core.tracker_store import InMemoryTrackerStore
from rasa.shared.core.domain import Domain
kafka_broker = KafkaEventBroker(url='localhost:9092',
domain = Domain.load("domain.yml")
tracker_store = InMemoryTrackerStore(domain=domain, event_broker=kafka_broker)

The url argument can be either a list of broker addresses or a single one. If only one broker address is available, the client will connect to it and request the cluster Metadata. Therefore, the remaining brokers in the cluster can be discovered automatically through the data served by the first connected broker.

To pass more than one broker address as argument, they must be passed in a list of strings. e.g.:

kafka_broker = KafkaEventBroker(host=['kafka_broker_1:9092',

Authentication and Authorization

Rasa's Kafka producer accepts two types of security protocols: SASL_PLAINTEXT and SSL.

For development environment, or if the brokers servers and clients are located into the same machine, you can use simple authentication with SASL_PLAINTEXT. By using this protocol, the credentials and messages exchanged between the clients and servers will be sent in plaintext. Thus, this is not the most secure approach, but since it's simple to configure, it is useful for simple cluster configurations. SASL_PLAINTEXT protocol requires the setup of the username and password previously configured in the broker server.

kafka_broker = KafkaEventBroker(host='kafka_broker:9092',

If the clients or the brokers in the kafka cluster are located in different machines, it's important to use the SSL protocol to ensure encryption of data and client authentication. After generating valid certificates for the brokers and the clients, the path to the certificate and key generated for the producer must be provided as arguments, as well as the CA's root certificate.

kafka_broker = KafkaEventBroker(host='kafka_broker:9092',

If the ssl_check_hostname parameter is enabled, the clients will verify if the broker's hostname matches the certificate. It's used on client's connections and inter-broker connections to prevent man-in-the-middle attacks.

Implementing a Kafka Event Consumer

The parameters used to create a Kafka consumer are the same as those used in the producer creation, according to the security protocol being used. The following implementation shows an example:

from kafka import KafkaConsumer
from json import loads
consumer = KafkaConsumer('rasa_events',
value_deserializer=lambda m: json.loads(m.decode('utf-8')),
for message in consumer:

SQL Event Broker

It is possible to use an SQL database as an event broker. Connections to databases are established using SQLAlchemy, a Python library which can interact with many different types of SQL databases, such as SQLite, PostgreSQL and more. The default Rasa installation allows connections to SQLite and PostgreSQL databases. To see other options, please see the SQLAlchemy documentation on SQL dialects.

Adding a SQL Event Broker Using the Endpoint Configuration

To instruct Rasa to save all events to your SQL event broker, add an event_broker section to your endpoints.yml. For example, a valid SQLite configuration could look like this:

type: SQL
dialect: sqlite
db: events.db

PostgreSQL databases can be used as well:

type: SQL
port: 5432
dialect: postgresql
username: myuser
password: mypassword
db: mydatabase

With this configuration applied, Rasa will create a table called events on the database, where all events will be added.