-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathecho.py
56 lines (44 loc) · 1.77 KB
/
echo.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from bifrost.common.service import Service
import asyncio
class Echo(Service):
def __init__(self):
super().__init__() # Setup RabbitMQ and Subscribe for autoconfig
#pending = io.Task.all_tasks()
#self.loop.run_until_complete(io.gather(*pending))
self.start()
async def reconfigure(self, topic, data, reply):
# Accept ther reconfig message, config yaml is in body
#print(f'Got Reconfig {message=}')
# Apply standard reconfig
await super().reconfigure(topic, data, reply)
return
async def echo_alice(self, topic, data, reply):
#print(f'{channel=} {method=} {properties=} {body=}')
print(f'Alice {" ".join(data)}')
async def echo_bob(self, topic, data, reply):
print(f'Bob {" ".join(data)}')
async def echo_mr_x(self, topic, data, reply):
print(f'FOR YOUR EYES ONLY: {data}')
async def echo_everyone(self, topic, data, reply):
print(f'Hello!')
class Hello(Service):
def __init__(self):
self.mr_x = "It's a mystery"
self.sleep = 1
super().__init__()
self.loop.create_task(self.produce())
self.start()
async def produce(self):
while self.running:
# Say something to Alice and Bob
await self.publish('Hello.Bob',
['The Builder'])
await self.publish('Hello.Alice',
['In', 'Wonderland'])
await self.publish('Hello.Mr_x',
str(self.mr_x))
await asyncio.sleep(self.sleep)
async def reconfigure(self, topic, data, reply):
# We don't do much, so we just use the standard reconfigure
await super().reconfigure(topic, data, reply)
return