Format
All events are streamed to the broker as serialized dictionaries every time the tracker updates its state. An example event emitted from thedefault
tracker looks like this:
event field takes the event’s type_name (for more on event
types, check out the events docs).
Kafka Event Broker
Kafka is recommended for all assistants at scale. Kafka is a requirement when streaming events to Rasa Pro Services or Rasa Studio. Rasa uses the confluent-kafka library, a Kafka client written in Python.How to consume events in Rasa AnalyticsTo check how to configure Rasa Analytics to consume events from Kafka, please refer to the
Analytics documentation.
Configuration
To use Kafka as an event broker in Rasa, you need to set it as anevent_broker in your endpoints.yml file.
For Kafka, Rasa supports following properties in event_broker section:
endpoints.yml
Partition Key
Rasa’s Kafka producer can optionally be configured to partition messages by conversation ID. This can be configured by settingpartition_by_sender in the endpoints.yml file to True.
By default, this parameter is set to False and the producer will randomly assign a partition to each message.
Authentication and Authorization
Rasa’s Kafka producer accepts the following types of security protocols:SASL_PLAINTEXT, SSL, PLAINTEXT
and SASL_SSL.
For development environments, or if the brokers servers and clients are located
into the same machine, you can use simple authentication with SASL_PLAINTEXT or 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.
If the clients or the brokers in the kafka cluster are located in different
machines, it’s important to use the SSL or SASL_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.
When using the SASL_PLAINTEXT and SASL_SSL protocols, the sasl_mechanism can be
optionally configured and is set to PLAIN by default. Valid values for sasl_mechanism
are: PLAIN, GSSAPI, OAUTHBEARER, SCRAM-SHA-256, and SCRAM-SHA-512.
If GSSAPI is used for the sasl_mechanism, you will need to additionally install
python-gssapi and the necessary C library
Kerberos dependencies.
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.
Using IAM roles to authenticate to AWS Managed Streaming for Apache Kafka (MSK)
New in 3.14You can use IAM authentication to connect to AWS MSK without needing to provide a username
and password.
IAM_CLOUD_PROVIDER: Set this toaws.AWS_DEFAULT_REGION: Set this to the AWS region where your MSK cluster is located.KAFKA_MSK_AWS_IAM_ENABLED: Set this totrueto enable IAM authentication for MSK connections, otherwise leave it unset or set tofalse.
endpoints.yml file to use the
SASL_SSL security protocol and OAUTHBEARER SASL mechanism, as well as provide the path to the
root certificate from Amazon Trust Services in the ssl_cafile property.
endpoints.yml
Example Configurations
Without authentication
To set up Rasa with Kafka which does not require authentication nor TLS handshake, use following config as an example:endpoints.yml
endpoints.yml
With authentication
To set up Rasa with Kafka which requires authentication but does not use TLS handshake, use following config as an example:endpoints.yml
endpoints.yml
GSSAPI, OAUTHBEARER, SCRAM-SHA-256 or SCRAM-SHA-512 if your broker is configured to use it for the
exposed URL endpoint.
Sending Events to Multiple Queues
Kafka does not allow you to configure multiple topics. However, multiple consumers can read from the same queue as long as they are in different consumer groups. Each consumer group will process all events independent of each other (in a sense, each group has their own reference to the last event they have processed). Kafka: The Definitive GuideDisabling Publishing of Un-anonymised Events
You can configure the event broker to not publish un-anonymised events to the configured topic. This is done by setting thestream_pii parameter in the endpoints.yml file to false.
Sending Anonymized Events
If you have the PII management capability enabled, you can configure the event broker to publish anonymised events to a different topic. This is done by setting theanonymization_topics parameter in the endpoints.yml file to a list of topics.
The event broker will publish anonymised events to the specified topics when the PII management capability is enabled.
Non-Blocking Publishing
New in 3.17You can configure Kafka to publish events without blocking the event loop by setting
type: concurrent_kafka instead of type: kafka.type: kafka publishes events synchronously on the event loop. Each publish call waits for the Kafka broker to acknowledge the event before returning.
For latency-sensitive deployments, use type: concurrent_kafka instead. This variant offloads publishing to a background thread pool so the event loop is never blocked by Kafka I/O or retry delays.
endpoints.yml
Ordering with multiple workersWhen
executor_max_workers is greater than 1, concurrent retries can reorder events for the same sender. Set partition_by_sender: True to ensure events for a given conversation always land on the same Kafka partition, but note that retry races between threads may still affect ordering within a partition. For strict ordering guarantees, keep executor_max_workers: 1 (the default).Pika Event Broker for RabbitMQ
Rasa uses Pika , the Python client library for RabbitMQ.Configuration
To use RabbitMQ as an event broker in Rasa, you need to set it as anevent_broker in your endpoints.yml file.
For RabbitMQ, Rasa supports following properties in even_broker section:
endpoints.yml
RABBITMQ_SSL_CLIENT_CERTIFICATE: path to the SSL client certificateRABBITMQ_SSL_CLIENT_KEY: path to the SSL client key
RABBITMQ_SSL_KEY_PASSWORD environment variable - please use a key file that is not encrypted instead.
Example Configurations
To set up Rasa with Pika for RabbitMQ use following config as an example:endpoints.yml
Adding a Pika Event Broker in Python
Here is how you add it using Python code: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’sstart_consuming() method with a callback action. Here’s a simple
example:
Sending Events to Multiple Queues
You can specify multiple event queues to publish events to. This should work for all event brokers supported by Pika (e.g. RabbitMQ)Disabling Publishing of Un-anonymised Events
By default, Rasa will publish un-anonymised events to the configured queues. If you want to disable this and only publish anonymized events, setstream_pii: false in your event_broker configuration.
Publishing Anonymized Events
If you want to publish anonymized events to a different queue, you can set theanonymization_queues property in your event_broker configuration.
This should be a list of queues to publish anonymized events to.
By default, this is set to an empty list, which means that anonymized events will not be published to any queue.
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. To set up Rasa with SQL event broker the following steps are required:- Add required configuration to your
endpoints.yml
endpoints.yml
endpoints.yml
- To start the Rasa server using your SQL backend, add the
--endpointsflag, e.g.:
FileEventBroker
It is possible to use theFileEventBroker as an event broker. This implementation will log events to a file in json format.
You can provide a path key in the endpoints.yml file if you wish to override the default file name: rasa_event.log.
Custom Event Broker
If you need an event broker which is not available out of the box, you can implement your own. This is done by extending the base classEventBroker.
Your custom event broker class must also implement the following base class methods:
from_endpoint_config: creates anEventBrokerobject from the endpoint configuration. (source code - see for signature).publish: publishes a json-formatted Rasa event into an event queue. (source code - see for signature).is_ready: determine whether the event broker is ready. (source code - see for signature).close: close the connection to an event broker. (source code - see for signature).
__init__ method of your custom event broker class must also implement the instance attribute self.stream_pii
to indicate if the event broker should stream un-anonymised events or not. The default value should be True.
To set up Rasa with your custom event broker the following steps are required:
- Add required configuration to your
endpoints.yml
endpoints.yml
- To start the Rasa server using your custom backend, add the
--endpointsflag, e.g.: