zeromq / chumak

Pure Erlang implementation of ZeroMQ Message Transport Protocol.
Mozilla Public License 2.0
197 stars 47 forks source link

Re-Implement zguide examples in Chumak #11

Open drozzy opened 7 years ago

drozzy commented 7 years ago

Re-implement all the zguide Erlang examples in Chumak: https://github.com/booksbyus/zguide/tree/master/examples

This will serve to document the library and iron out any quirks in the library.

drozzy commented 5 years ago

Looking for contributors.

mk270 commented 5 years ago

if you could get me an example of actually using chumak in a gen_server, I'd happily help sort ouf the rest of the docs. The examples/ aren't idiomatic for some people, even those experienced in Erlang, to get as far as hello world.

drozzy commented 5 years ago

I haven’t looked into this in a while, so I’m afraid I can’t help. Hopefully someone can figure out how to make it idiomatic. Feel free to hack the core code. My intent was to just provide a starting point.

shishirpy commented 3 years ago

I would like to help with this, @mk270 could you tell you mean by idiomatic examples, I have tried the following code example and it is working:

The server module is:

-module(hwserver).
-export([main/0]).

main() ->
    application:start(chumak),
    {ok, Socket} = chumak:socket(rep, "my-rep"),
    io:format("~p", [Socket]),
    {ok, Pid} = chumak:bind(Socket, tcp, "localhost", 5555),
    loop(Socket).

loop(Socket) ->
    {ok, RecvMessage} = chumak:recv(Socket),

    io:format("Received request : ~p\n", [RecvMessage]),

    timer:sleep(1000),

    chumak:send(Socket, "World"),
    loop(Socket).

and the client module is:

-module(hwclient).
-export([main/0]).

main() ->
    application:start(chumak),
    {ok, Socket} = chumak:socket(req, "my-req"),
    {ok, Pid} = chumak:connect(Socket, tcp, "localhost", 5555),
    loop(Socket).

loop(Socket) ->
    chumak:send(Socket, "Hello"),
    {ok, RecvMessage} = chumak:recv(Socket),
    io:format("Recv Reply: ~p\n", [RecvMessage]),
    loop(Socket).
shishirpy commented 3 years ago

@drozzy what is the equivalent of socket.close() in chumak? I am trying to implement the lazy pirate pattern, where one has to close the socket and restart a new one in no response arrives in fixed timeout.

drozzy commented 3 years ago

As I remember there was some discussion similar to this before, but I don't think anything was actually decided: https://github.com/zeromq/chumak/pull/19 https://github.com/zeromq/chumak/issues/18

shishirpy commented 1 year ago

@drozzy any idea how to have an unblocking receive command? Trying to implement msreader https://github.com/booksbyus/zguide/blob/master/examples/Erlang/msreader.es

drozzy commented 1 year ago

@shishirpy you may have more luck on Erlang discussion forums: https://www.erlang.org/community I'm not actively maintaining this - I only try to keep up with MRs.