Introduction
The AdmiralCloud Event Service processes messages from a message queue (SQS queue). These messages usually contain events like model changes or other events (e.g. createEmbedLink) and you can subscribe to these events.
Every subscription contains a set of instructions that will be fired if the message content and the subscription match.
Subscriptions can be recurring (flag 0), one-time (flag 2) or once (flag 3). Every execution of a subscription is logged for auditing.
One-time subscriptions are checked until they are fulfilled and marked as processed. Subscriptions of type “once” are only checked and processed once, regardless of the result from instructions.
Data Model
Subscriptions have the following fields
Field | Type | Description |
---|---|---|
name | string | Name of the event this subscription listens to |
flag | integer | 0 -> recurring 2 -> one-time (until fulfilled) 3 -> once (regardless of outcome) 9 -> processed |
customerId | integer | Must match with the customerId of the message |
conditions | object | Object with optional conditions. If set, they must match with the message |
instructions | array | Array of objects with instructions to be executed |
notes | string | Optional notes for this subscriptions |
lastExecutedStatus | integer | 200 -> successfully executed 500 -> execution failed |
lastExecutedMessage | string | If execution fails, this field contains the error message |
lastExecuted | integer | unix timestamp of the last execution time for this subscription |
Conditions
Field | Type | Description |
---|---|---|
methods | array | Optional methods to listen to (create, update, destroy) |
payload | object | Payload must match the message payload |
Messages
SQS Messages are objects with the following data
Field | Type | Description |
---|---|---|
name | string | Name of the event (subscriptions will listen to this name) |
customerId | integer | Must match with the customerId of the subscriptions |
method | string | Method of modelChange (create, update, destroy) – must match the subscription’s conditions |
payload | object | An object with data for the subscription |
Examples
Let’s assume the API sends an event into the message queue after a new mediacontainer is created (event ‘modelChange:mediaContainer’). We now want to add a subscriptions that listens to new mediacontainers of type video and then add a license (template 10) and send an email to ‘jane@admiralcloud.com’.
Create a subscription listening to that event
{
name: 'modelChange:mediaContainer',
flag: 0 // recurring
customerId: 12345,
conditions: {
method: 'create',
payload: {
type: 'video'
}
},
instructions: [{
type: 'api',
method: 'post',
path: 'v5/license',
controller: 'license',
action: 'create',
payload: {
mediaContainerId: ':mediaContainerId', // will be replaced with the mediaContainerId from message - ':mediaContainerId' is a placeholder
templateId: 10,
start: 1234567890, // unix timestamp
types: ['all']
}
},
{
type: 'email',
template:'mediaContainerCreated',
subject: 'New mediaContainer available',
to: [
{
recipient: 'jane@admiralcloud.com',
language: 'en'
}
],
mediaContainerIds: [':mediaContainerId']
}]
}
Send media as attachment
You can send the original media as attachment if you assign a specific security group.
Setting replyTo to TRUE means, that the reply-to address is set to the email of the user who made the controlGroup change. That’s why we have to set userId as “:creatorId”.
{
"name":"modelChange:controlGroupToMediaContainer",
"flag":0,
"conditions":{
"methods":[
"create"
],
"payload":{
"controlGroupId":12345
}
},
"instructions":[
{
"type":"api",
"method":"post",
"path":"v5/search",
"controller":"search",
"action":"search",
"payload":{
"searchTerm":":mediaContainerId",
"field":"id"
}
},
{
"type":"email",
"template":"mediacontainer_attachment",
"replyTo":true,
"attachment":true,
"to":[
{
"recipient":"jane@admiralcloud.com",
"language":"de"
}
],
"languageData":{
"reason":"Die Datei wurde der Sicherheitsgruppe ABC Test zugeordnet",
"container_comment":":response.hits.hits[0]._source.container_comment"
},
"mediaContainerIds":[
":mediaContainerId"
],
"userId":":creatorId"
}
]
}