This repository was archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
57 lines (49 loc) · 1.43 KB
/
example.py
File metadata and controls
57 lines (49 loc) · 1.43 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import json
import time
import logging.config
from streamdal import (
Audience,
StreamdalClient,
StreamdalConfig,
ProcessRequest,
OPERATION_TYPE_CONSUMER,
EXEC_STATUS_TRUE,
)
def main():
logging.basicConfig()
client = StreamdalClient(
cfg=StreamdalConfig(
service_name="service",
dry_run=False,
streamdal_url="localhost:8082",
streamdal_token="1234",
audiences=[
Audience(
operation_name="demo-operation",
component_name="kafka",
operation_type=OPERATION_TYPE_CONSUMER,
)
],
)
)
while not client.cfg.exit.is_set():
time.sleep(5)
req = ProcessRequest(
operation_type=OPERATION_TYPE_CONSUMER,
operation_name="demo-operation",
component_name="kafka",
data=b'{"object": {"email": "mark@streamdal.com"}}',
)
res = client.process(req)
# Check that process() completed successfully
if res.status == EXEC_STATUS_TRUE:
print("Success processed payload")
data = json.loads(res.data)
print("Response:", json.dumps(data, indent=2))
else:
print("Failed to process payload")
print("Error:", res.status_message)
print("done")
if __name__ == "__main__":
main()