/
service_a.py
33 lines (26 loc) 路 1.25 KB
/
service_a.py
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
from typing import Any
import tomodachi
from tomodachi import aws_sns_sqs, aws_sns_sqs_publish
from tomodachi.protocol import JsonBase
@tomodachi.service
class ServiceA(tomodachi.Service):
name = 'example_service_a'
message_protocol = JsonBase
options = {
'aws_sns_sqs': {
'region_name': None, # specify AWS region (example: 'eu-west-1')
'aws_access_key_id': None, # specify AWS access key (example: 'AKIAXNTIENCJIY2STOCI')
'aws_secret_access_key': None # specify AWS secret key
},
'aws_endpoint_urls': {
'sns': None, # For example 'http://localhost:4575' if localstack is used for testing
'sqs': None # For example 'http://localhost:4576' if localstack is used for testing
}
}
@aws_sns_sqs('example-pubsub-new-message', competing=True)
async def new_message(self, data: Any) -> None:
self.log('Received data (function: new_message) - "{}"'.format(data))
callback_data = 'message received: "{}"'.format(data)
await aws_sns_sqs_publish(self, callback_data, topic='example-pubsub-callback', wait=True)
async def _started_service(self) -> None:
self.log('Subscribing to messages on topic "example-pubsub-new-message"')