Skip to content

Commit f29a041

Browse files
committed
feat: fix bugs
1 parent 17646f6 commit f29a041

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,33 @@ pip install stallion-python-sdk
2121
### Client
2222
Create a client:
2323
```python
24-
from stallion_python_sdk import Client
24+
# importing Client module
25+
from stallion import Client
2526

27+
# creating a client
28+
# with given stallion server url
2629
c = Client(url="localhost:9090")
2730
```
2831

2932
### Publish
3033
```python
34+
# publish an object on a topic
3135
c.Publish("book", {'author': "Amirhossein", 'name': "Stallion"})
3236
```
3337

3438
### Subscribe
3539
```python
40+
# creating a handler
41+
# any published object will be given to this handler as data
3642
def handler(data):
37-
print(data)
43+
print(f'{data['author']}: {data['name']})
3844
45+
# subscribe over a topic with given handler
3946
c.Subscribe("book", handler)
4047
```
4148

4249
### Unsubscribe
4350
```python
51+
# unsubscribe from a topic
4452
c.Unsubscribe("book")
4553
```

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[metadata]
22
name = stallion-python-sdk
3-
version = 1.2.1
3+
version = 1.2.2
44
author = amirhnajafiz
55
author_email = najafizadeh21@gmail.com
66
description = SDK for Stallion message broker
77
long_description= file: README.md
88
long_description_content_type = text/markdown
9+
url = https://github.com/amirhnajafiz/stallion-python-sdk
910
classifiers =
1011
Programming Language :: Python :: 3
1112
License :: OSI Approved :: MIT License

src/stallion/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import threading
2+
from time import sleep
23

34
from parser import *
45
from network import Network
@@ -57,16 +58,22 @@ def __read_data_from_server__(self):
5758
def Publish(self, topic, data):
5859
self.__net.write(jsonEncode(newMessage(topic=topic, data=data)))
5960

61+
sleep(0.001)
62+
6063
"""
6164
Subscribe over a topic.
6265
"""
6366
def Subscribe(self, topic, handler):
6467
self.__handlers[topic] = handler
6568
self.__net.write(jsonEncode(newMessage(type=2, topic=topic)))
69+
70+
sleep(0.001)
6671

6772
"""
6873
Unsubscribe from a topic.
6974
"""
7075
def Unsubscribe(self, topic):
7176
self.__handlers.pop(topic)
7277
self.__net.write(jsonEncode(newMessage(type=3, topic=topic)))
78+
79+
sleep(0.001)

tests/test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from time import sleep
21
from stallion.client import Client
32

43

@@ -14,13 +13,9 @@ def handler(data):
1413
# create client
1514
c = Client(url="localhost:9090")
1615

17-
sleep(1)
18-
1916
# subscribe over a topic
2017
c.Subscribe("book", handler)
2118

22-
sleep(1)
23-
2419
# publish messages over a topic
2520
c.Publish("book", {'author': "Amirhossein", 'name': "Stallion"})
2621

0 commit comments

Comments
 (0)