#! /usr/bin/env escript
%%
%% Demonstrate identities as used by the request-reply pattern.
%%
main(_) ->
{ok, Context} = erlzmq:context(),
{ok, Sink} = erlzmq:socket(Context, router),
ok = erlzmq:bind(Sink, "inproc://example"),
%% First allow 0MQ to set the identity
{ok, Anonymous} = erlzmq:socket(Context, req),
ok = erlzmq:connect(Anonymous, "inproc://example"),
ok = erlzmq:send(Anonymous, @<@@[[/span]][[span style="color:#BA2121"]]"ROUTER uses a generated UUID"[[/span]][[span style="color:#666666"]]@@>@),
erlzmq_util:dump(Sink),
%% Then set the identity ourself
{ok, Identified} = erlzmq:socket(Context, req),
ok = erlzmq:setsockopt(Identified, identity, @<@@[[/span]][[span style="color:#BA2121"]]"Hello"[[/span]][[span style="color:#666666"]]@@>@),
ok = erlzmq:connect(Identified, "inproc://example"),
ok = erlzmq:send(Identified,
@<@@[[/span]][[span style="color:#BA2121"]]"ROUTER socket uses REQ's socket identity"[[/span]][[span style="color:#666666"]]@@>@),
erlzmq_util:dump(Sink),
erlzmq:close(Sink),
erlzmq:close(Anonymous),
erlzmq:close(Identified),
erlzmq:term(Context).