Django Integration¶
Note
This guide simply points out the differences between standalone Relé and the Django integration. The basics about publishing and subscribing are described in the First Steps section.
Publishing¶
To configure Relé, our settings may look something like:
RELE = {
'GC_CREDENTIALS_PATH': 'photo_project/settings/dummy-credentials.json',
'MIDDLEWARE': [
'rele.contrib.LoggingMiddleware',
'rele.contrib.DjangoDBMiddleware',
],
'APP_NAME': 'photo-imaging',
}
The only major difference here is that we are using the rele.contrib.DjangoDBMiddleware
.
This is important to properly close DB connections.
Important
If you plan on having your subscriber connect to the database, it is vital that the Django settings.CONN_MAX_AGE is set to 0.
Once the topic is created and our Django application has the proper configuration defined in Settings, we can start publishing to that topic.
Subscribing¶
Since the Django integration comes with python manage.py runrele
command, we must name the file
where we define our subscribers subs.py
. runrele
will auto-discover all decorated
subscriber methods in a defined Django app and register/create the subscriptions for us.
Subscribing follows the same method as before.
Consuming¶
Unlike what is described in Consuming, the Django integration provides a very convenient command.
By running python manage.py runrele
, worker process will autodiscover any properly decorated @sub
function in the subs.py
file and create the subscription for us.
Once the process is up and running, we can publish and consume.