Certain actions on the website trigger events that are handed to a RabbitMQ queueing server. These events and their contents are described here.
1. Delivery mode
All events that are sent to the queue MUST be sent with delivery_mode = 2 (persistent messages).
2. Exchange name
All events are sent to the exchange extensionschoolevents
3. Mail events
Mail is sent through the queue server in order to accomplish asynchronous mail sending (keep the webserver from blocking).
A mail event is identified by the routing key mail.sending
The body of a mail event consists of a JSON-encoded dictionary of the following form:
{ 'from_email': 'sender@my.domain', 'recipient_list': [ 'recipient1@gmail.com', 'recipient2@hotmail.com' ], 'subject': 'The subject line for this message', 'message': 'A multi-line string holding the text version of this message', 'html_message': 'A multi-line string holding the html-version of this message', }
The html_message field is optional.
Example of an e-mail event:
import pika import json credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) connection = pika.BlockingConnection(pika.ConnectionParameters( host=SETTINGS.queuehost,credentials=credentials)) channel = connection.channel() message = { 'from_email': 'sender@my.domain', 'recipient_list': [ 'recipient1@gmail.com', 'recipient2@hotmail.com' ], 'subject': 'The subject line for this message', 'message': 'A multi-line string holding the text version of this message', 'html_message': 'A multi-line string holding the html-version of this message', } channel.basic_publish( exchange='extensionschoolevents', routing_key='mail.sending', body=json.dumps(message), properties=pika.BasicProperties(delivery_mode=2), )
4. Learner events
4.1. Add
This event must be sent when a new learner has registered. At this moment the learner MUST also have provided a password for his registration.
The routing key for this event is learner.add
The body of a learner.add event consists of a JSON-encoded dictionary of the following object:
{ 'learner': { 'id': 15, 'email': 'a.g.degroot@hotmail.com', 'userlevel': 1, 'newslettersubscription': false, 'surname': 'Groot', 'firstname': 'Anne', 'nameprefix': 'de', 'initials': 'A.G.', 'gender': 'Female', } 'password': 'plaintext password for this learner' }
The 'learner' key holds an encoding of the django-object from learners.models
Example of a learner.add event:
import pika import jsonpickle credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) connection = pika.BlockingConnection(pika.ConnectionParameters( host=SETTINGS.queuehost,credentials=credentials)) channel = connection.channel() learner = learners.models.Learner.objects.get(id=learnerid) message = { 'learners': learner, 'password': learnerpassword, } channel.basic_publish( exchange='extensionschoolevents', routing_key='learner.add', body=jsonpickle.encode(message), properties=pika.BasicProperties(delivery_mode=2), )
4.2. Update
This event must be sent when a new learner has registered. At this moment the learner MUST also have provided a password for his registration.
The routing key for this event is learner.update
The body of a learner.add event consists of a JSON-encoded dictionary of the following object:
{ 'learner': { 'id': 15, 'email': 'a.g.degroot@hotmail.com', 'userlevel': 1, 'newslettersubscription': false, 'surname': 'Groot', 'firstname': 'Anne', 'nameprefix': 'de', 'initials': 'A.G.', 'gender': 'Female', } 'password': 'plaintext password for this learner' }
The 'learner' key holds an encoding of the django-object from learners.models
The 'password' key is optional and should only be filled in case of a password change.
Example of a learner.update event:
import pika import jsonpickle credentials = pika.PlainCredentials(SETTINGS.queueuser, SETTINGS.queuepassword) connection = pika.BlockingConnection(pika.ConnectionParameters( host=SETTINGS.queuehost,credentials=credentials)) channel = connection.channel() learner = learners.models.Learner.objects.get(id=learnerid) message = { 'learners': learner, 'password': learnerpassword, } channel.basic_publish( exchange='extensionschoolevents', routing_key='learner.update', body=jsonpickle.encode(message), properties=pika.BasicProperties(delivery_mode=2), )