Eventbus ServiceΒΆ

Example Eventbus Event:

{
    "topic"        : "hoth.model.processed",
    "uuid"         : "82ce7190-71c6-4bbe-b0e2-5f9cfd039854",
    "payload"      : {
        "name"      : "My_Model",
        "uri"       : "https://model.authentise.com/models/82ce7190-71c6-4bbe-b0e2-5f9cfd039854/",
    },
}

Many of Authentise’s services make use of Eventbus. Some connect to https://events.authentise.com/ and they recieve constant updates about data being manipulated in our system. The only thing that is required for using this is a valid session either by logging in or using an API token. Let’s take for example the following:

#!/usr/bin/env python3
import requests
import json

response = session.get('https://events.authentise.com/', stream=True)
print(response.status_code)
print(response.headers.items())
for line in response.iter_lines():
    if line:
        print(line)

Now this is to listen to data that is being populated to eventbus. It grabs the data that is being returned and simply prints it out. Now lets look at an example of actually using the data returned.

#!/usr/bin/env python3
import requests
import json

response = session.get('https://events.authentise.com/', stream=True)
print(response.status_code)
print(response.headers.items())
for line in response.iter_lines():
    if line:
        data = json.loads(line.decode())
        if hoth.model.processed:
          print("Model: {}, is done processing. It is now ready for use.").format(data['uuid'])

First off this is using the example payload from above. Now instead of simply printing the line we are decoding the json data. Then we are checking if its a topic we care about and then afterwords reacting to this by informing the user that their model is now done processing. We are also able to pull out any model information like the uuid or possibly a payload that is present in the published event.