Skip to content

Commit

Permalink
Update documentation for SQL event broker.
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Jul 25, 2019
1 parent 1bad671 commit 84c41b4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
56 changes: 54 additions & 2 deletions docs/api/event-brokers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ tracker looks like this:
The ``event`` field takes the event's ``type_name`` (for more on event
types, check out the :ref:`events` docs).

Rasa enables two possible brokers producers: Pika Event Broker and Kafka Event Broker.
Rasa enables three possible broker types:

- `Pika Event Broker`_
- `Kafka Event Broker`_
- `SQL Event Broker`_

Pika Event Broker
-----------------
Expand Down Expand Up @@ -108,7 +112,7 @@ example:
Kafka Event Broker
------------------

It is possible to use `Kafka <https://kafka.apache.org/>`_ as main broker to you events. In this example
It is possible to use `Kafka <https://kafka.apache.org/>`_ as main broker for your events. In this example
we are going to use the `python-kafka <https://kafka-python.readthedocs.io/en/master/usage.html>`_
library, a Kafka client written in Python.

Expand Down Expand Up @@ -231,3 +235,51 @@ according to the security protocol being used. The following implementation show
for message in consumer:
print(message.value)
SQL Event Broker
-----------------

It is possible to use an SQL database as an event broker. Connections to databases are established using
`SQLAlchemy <https://www.sqlalchemy.org/>`_, a Python library which can interact with many
different types of SQL databases, such as `SQLite <https://sqlite.org/index.html>`_,
`PostgreSQL <https://www.postgresql.org/>`_ 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 <https://docs.sqlalchemy.org/en/13/dialects/index.html>`_.


Adding a SQL Event Broker Using the Endpoint Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can use an endpoint configuration file to instruct Rasa to stream
all events to your SQL event broker. To do so, add a ``event_broker`` section to your
endpoint configuration, e.g. ``endpoints.yml``. For example, a valid SQLite configuration
could look like the following:

.. code-block:: yml
event_broker:
type: SQL
dialect: sqlite
db: events.db
PostgreSQL databases can be used as well:

.. code-block:: yml
event_broker:
type: SQL
host: 127.0.0.1
port: 5432
dialect: postgresql
username: myuser
password: mypassword
db: mydatabse
Then, instruct Rasa to use the endpoint configuration and SQL producer by adding
``--endpoints <path to your endpoint configuration`` as following example:

.. code-block:: shell
rasa run -m models --endpoints endpoints.yml
Rasa will then create a table called ``events``, where all events will be added.
2 changes: 1 addition & 1 deletion rasa/core/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def from_endpoint_config(
return None
elif broker_config.type == "pika" or broker_config.type is None:
return PikaProducer.from_endpoint_config(broker_config)
elif broker_config.type == "sql":
elif broker_config.type.lower() == "sql":
return SQLProducer.from_endpoint_config(broker_config)
elif broker_config.type == "file":
return FileProducer.from_endpoint_config(broker_config)
Expand Down

0 comments on commit 84c41b4

Please sign in to comment.