forked from triggerflow/triggerflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_world.py
More file actions
29 lines (18 loc) · 996 Bytes
/
hello_world.py
File metadata and controls
29 lines (18 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
from triggerflow import Triggerflow, CloudEvent
from triggerflow.functions import PythonCallable
from triggerflow.eventsources.rabbit import RabbitMQEventSource
tf_client = Triggerflow(endpoint='${TRIGGERFLOW_ENDPOINT}', user='admin', password='admin')
rabbitmq_source = RabbitMQEventSource(amqp_url='amqp://guest:guest@${RABBITMQ_BROKER}/', queue='My-Queue')
tf_client.create_workspace(workspace_name='test', event_source=rabbitmq_source)
def my_action(context, event):
context['message'] += 'World!'
activation_event = CloudEvent().SetEventType('test.event.type').SetSubject('Test')
tf_client.add_trigger(trigger_id='MyTrigger',
event=activation_event,
action=PythonCallable(my_action),
context={'message': 'Hello '})
rabbitmq_source.publish_cloudevent(activation_event)
time.sleep(3) # Let some time for the DB to be updated
trg = tf_client.get_trigger('MyTrigger')
print(trg['context']['message'])