Skip to content

Commit a83a6d2

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 6fc11c3 + 5f37e1f commit a83a6d2

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

client_example.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ def main():
1010

1111
# wait for initialization
1212
time.sleep(5) # TODO: extract 'ready' event from thread
13-
print(client.emit('event_test'))
14-
15-
time.sleep(3)
16-
print(client.broadcast('event_test'))
13+
client.emit('event_test')
14+
client.broadcast('event_test')
1715

1816

1917
if __name__ == '__main__':

moleculer/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,23 @@ def on_channel_open(self, channel):
1414
self.channel: Channel = channel
1515
self.add_on_channel_close_callback()
1616
info_queue = 'MOL.INFO.{node_id}'.format(node_id=self.NODE_ID)
17+
disconnect_queue = 'MOL.DISCONNECT.{node_id}'.format(node_id=self.NODE_ID)
1718
self.setup_queue(info_queue)
19+
self.setup_queue(disconnect_queue)
1820
self.channel.queue_bind(self.on_bindok, info_queue, 'MOL.INFO')
21+
self.channel.queue_bind(self.on_bindok, disconnect_queue, 'MOL.DISCONNECT')
1922
self.channel.basic_consume(self.process_info_packages, info_queue)
23+
self.channel.basic_consume(self.on_node_disconnect, disconnect_queue)
2024
self.discover_packet()
2125

2226
def process_info_packages(self, unused_channel, basic_deliver, properties, body):
2327
info_packet = json.loads(body)
2428
self.network.add_node(info_packet)
2529

30+
def on_node_disconnect(self, unused_channel, basic_deliver, properties, body):
31+
disconnect_package = json.loads(body)
32+
self.network.disconnect_node(disconnect_package['sender'])
33+
2634
def emit(self, event_name, data=None):
2735
candidates = self.get_emit_candidates(event_name)
2836
if len(candidates) == 0:
@@ -47,6 +55,12 @@ def broadcast(self, event_name, data=None):
4755
queue_name = 'MOL.EVENT.{node_id}'.format(node_id=node_id)
4856
self.channel.basic_publish('', queue_name, event_package)
4957

58+
def call(self):
59+
pass
60+
61+
def dcall(self):
62+
pass
63+
5064
def get_emit_candidates(self, event_name):
5165
service_names = set()
5266
for node_id, node_info in self.network.NODES.items():

setup.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from distutils.core import setup
2+
3+
setup(
4+
name = 'moleculer',
5+
packages = ['moleculer'], # this must be the same as the name above
6+
version = '0.1',
7+
description = 'Moleculer node and client for amqp with json serializer',
8+
author = 'Andrei Khaliaukin',
9+
author_email = 'endpoo@gmail.com',
10+
url = 'https://github.com/ToGoBananas/moleculer-python', # use the URL to the github repo
11+
download_url = 'https://github.com/ToGoBananas/moleculer-python/archive/0.1.tar.gz', # I'll explain this in a second
12+
keywords = ['moleculer', 'microservices'], # arbitrary keywords
13+
classifiers = [],
14+
)

0 commit comments

Comments
 (0)