Commit 674c8b15 authored by Robin Obůrka's avatar Robin Obůrka Committed by Robin Obůrka

dev: Rewrite dev environment to use msgloop

parent 2fe3688b
......@@ -5,18 +5,20 @@ import zmq
import sn
def main():
"""Plain lib version"""
ctx = sn.SN(zmq.Context.instance())
def setup():
class ExampleResources:
foo = "bar"
socket = ctx.get_socket("in")
return ExampleResources
while True:
msg = socket.recv_multipart()
mtype, data = sn.parse_msg(msg)
print(mtype, data)
def teardown(userdata):
print("teardown")
def process(envdata, userdata, msg_type, payload):
print(msg_type, payload)
if __name__ == "__main__":
main()
sn.sn_main("in_only", setup=setup, teardown=teardown, process=process)
......@@ -5,17 +5,22 @@ import zmq
import sn
def main():
"""Plain lib version"""
ctx = sn.SN(zmq.Context.instance())
def setup():
class ExampleResources:
foo = "bar"
socket_in = ctx.get_socket("in")
socket_out = ctx.get_socket("out")
return ExampleResources
while True:
msg = socket_in.recv_multipart()
socket_out.send_multipart(msg)
def teardown(userdata):
print("teardown")
def process(envdata, userdata, msg_type, payload):
print(msg_type, payload)
return msg_type, payload
if __name__ == "__main__":
main()
sn.sn_main("in_out", setup=setup, teardown=teardown, process=process)
......@@ -7,23 +7,29 @@ import zmq
import sn
def main():
"""Plain lib version"""
ctx = sn.SN(zmq.Context.instance())
def setup():
class ExampleResources:
foo = "bar"
socket = ctx.get_socket("out")
return ExampleResources
def teardown(userdata):
print("teardown")
def process(envdata, userdata):
while True:
data = {
"foo": "bar",
"foo": userdata.foo,
"ts": int(time.time()),
}
msg = sn.encode_msg("sentinel/dev/sn", data)
socket.send_multipart(msg)
print("PUB", data)
yield "sentinel/dev/sn", data
print("PUB", data)
time.sleep(1)
if __name__ == "__main__":
main()
sn.sn_main("out_only", setup=setup, teardown=teardown, process=process)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment