Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

push/pull pair with :streamer device example #36

Open
hxzrx opened this issue Jun 21, 2022 · 0 comments
Open

push/pull pair with :streamer device example #36

hxzrx opened this issue Jun 21, 2022 · 0 comments

Comments

@hxzrx
Copy link

hxzrx commented Jun 21, 2022

Hi,
The code below is an simple example of push/pull pair with :streamer device, and the backend workers run in threads, everything is OK!

(ql:quickload :pzmq)
(ql:quickload :bordeaux-threads)

(defun streamer-device (front back)
  (pzmq:with-sockets ((frontend :pull) (backend :push))
    (pzmq:bind frontend front)
    (pzmq:bind backend back)
    (dotimes (i 2)
      (pzmq:with-context nil
        (bt:make-thread (lambda ()
                          (pzmq:with-socket recv :pull
                            (pzmq:connect recv back)
                            (loop (format t "Streamer pulled a msg: ~d" (pzmq:recv-string recv))))))))
    (pzmq:device :streamer frontend backend)
    ;; Or use proxy
    #+:ignore(pzmq:proxy frontend backend (cffi:null-pointer))))

(defun send-streamer (endpoint)
  (pzmq:with-sockets ((sender :push))
    (pzmq:connect sender endpoint)
    (pzmq:send sender "hello")))

Tests with:

(bt:make-thread (lambda ()
                  (streamer-device "tcp://127.0.0.1:5558" "tcp://127.0.0.1:5559")))
(sleep 0.5)
(send-streamer "tcp://127.0.0.1:5558")

(bt:make-thread (lambda ()
                  (streamer-device "tcp://127.0.0.1:5561" "ipc://workers")))
(sleep 0.5)
(send-streamer "tcp://127.0.0.1:5561")

(bt:make-thread (lambda ()
                  (streamer-device "tcp://127.0.0.1:5560" "inproc://workers")))
(sleep 0.5)
(send-streamer "tcp://127.0.0.1:5560")
@hxzrx hxzrx changed the title streamer device with inproc failed Streamer device with inproc failed Jun 21, 2022
@hxzrx hxzrx changed the title Streamer device with inproc failed push/pull pair with :streamer device example Jun 24, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant