Closed micahrye closed 6 years ago
Hi!
The short answer is yes, you should continuously poll. However, you can put a proxy process in-between you and the polling process, that, say, only keeps the last message. This is erlang/elixir specific functionality. So you might do something like the last value caching example in zmq guide - only you can do it all in erlang/elixir itself: http://zguide.zeromq.org/php:chapter5#Last-Value-Caching
Basically, you should think about what behavior you want exactly, e.g. do you care about missing messages? What about duplicates? Do you always want to get a reply right away or do you want to get "None" if nothing was received recently? After you answer those questions, you can start designing the system around that. It requires a bit of a brain twist.
Good luck, and let me know if this was really confusing!
P.S.: Feel free to post code in Elixir as well.
Thanks for answer and code!
Closing for now. Please feel free to re-open if you have more questions.
This is a question, so you know I am newer to Elixir and this is the first time I have delved into pure Erlang code.
I was wondering if there is a simple way to flush the un-received messages, or get the most recent message, or get the length of queued messages?
A related question I have is if there are any issues with having connection to say a publisher and not checking the messages?
I am running a zmq publisher (in nodejs) and have the following subscriber:
-- Converted my Elixir to Erlang, hopefully no syntax errors --
This works and I get the expected msg from the publisher, but if I do not continue to execute
chumak:recv(pub_socket)
while the publisher is continuing to publish msgs, then when I do executechumak:recv(pub_socket)
it is an old msg. I would like to be able to get the most recent msg and flush the rest. Is that possible? Or am I suppose to be continuously checking?Thx