File tree Expand file tree Collapse file tree 4 files changed +19
-8
lines changed Expand file tree Collapse file tree 4 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -21,25 +21,33 @@ pip install stallion-python-sdk
21
21
### Client
22
22
Create a client:
23
23
``` python
24
- from stallion_python_sdk import Client
24
+ # importing Client module
25
+ from stallion import Client
25
26
27
+ # creating a client
28
+ # with given stallion server url
26
29
c = Client(url = " localhost:9090" )
27
30
```
28
31
29
32
### Publish
30
33
``` python
34
+ # publish an object on a topic
31
35
c.Publish(" book" , {' author' : " Amirhossein" , ' name' : " Stallion" })
32
36
```
33
37
34
38
### Subscribe
35
39
``` python
40
+ # creating a handler
41
+ # any published object will be given to this handler as data
36
42
def handler (data ):
37
- print (data)
43
+ print (f ' { data[ ' author ' ] } : { data[ ' name ' ] } )
38
44
45
+ # subscribe over a topic with given handler
39
46
c.Subscribe(" book" , handler)
40
47
```
41
48
42
49
# ## Unsubscribe
43
50
```python
51
+ # unsubscribe from a topic
44
52
c.Unsubscribe(" book" )
45
53
```
Original file line number Diff line number Diff line change 1
1
[metadata]
2
2
name = stallion-python-sdk
3
- version = 1.2.1
3
+ version = 1.2.2
4
4
author = amirhnajafiz
5
5
author_email = najafizadeh21@gmail.com
6
6
description = SDK for Stallion message broker
7
7
long_description = file: README.md
8
8
long_description_content_type = text/markdown
9
+ url = https://github.com/amirhnajafiz/stallion-python-sdk
9
10
classifiers =
10
11
Programming Language :: Python :: 3
11
12
License :: OSI Approved :: MIT License
Original file line number Diff line number Diff line change 1
1
import threading
2
+ from time import sleep
2
3
3
4
from parser import *
4
5
from network import Network
@@ -57,16 +58,22 @@ def __read_data_from_server__(self):
57
58
def Publish (self , topic , data ):
58
59
self .__net .write (jsonEncode (newMessage (topic = topic , data = data )))
59
60
61
+ sleep (0.001 )
62
+
60
63
"""
61
64
Subscribe over a topic.
62
65
"""
63
66
def Subscribe (self , topic , handler ):
64
67
self .__handlers [topic ] = handler
65
68
self .__net .write (jsonEncode (newMessage (type = 2 , topic = topic )))
69
+
70
+ sleep (0.001 )
66
71
67
72
"""
68
73
Unsubscribe from a topic.
69
74
"""
70
75
def Unsubscribe (self , topic ):
71
76
self .__handlers .pop (topic )
72
77
self .__net .write (jsonEncode (newMessage (type = 3 , topic = topic )))
78
+
79
+ sleep (0.001 )
Original file line number Diff line number Diff line change 1
- from time import sleep
2
1
from stallion .client import Client
3
2
4
3
@@ -14,13 +13,9 @@ def handler(data):
14
13
# create client
15
14
c = Client (url = "localhost:9090" )
16
15
17
- sleep (1 )
18
-
19
16
# subscribe over a topic
20
17
c .Subscribe ("book" , handler )
21
18
22
- sleep (1 )
23
-
24
19
# publish messages over a topic
25
20
c .Publish ("book" , {'author' : "Amirhossein" , 'name' : "Stallion" })
26
21
You can’t perform that action at this time.
0 commit comments