Permalink
Browse files

Merge pull request #150 from igorw/xreq-xrep

Replace old XREP and XREQ examples with ROUTER and DEALER
  • Loading branch information...
2 parents f5fe47b + 0746a13 commit 49975cf88f33282ee451330241b79dc4ccdf472d @hintjens hintjens committed Jan 5, 2012
Showing with 294 additions and 294 deletions.
  1. +2 −2 articles/src/multithreading/zmsg.c
  2. +2 −2 examples/Ada/zmq-examples-multi_thread_server.adb
  3. +6 −6 examples/C#/asyncsrv.cs
  4. +3 −3 examples/C#/identity.cs
  5. +2 −2 examples/C#/lruqueue.cs
  6. +2 −2 examples/C#/lruqueue2.cs
  7. +2 −2 examples/C#/msgqueue.cs
  8. +2 −2 examples/C#/mtserver.cs
  9. +2 −2 examples/C#/rrbroker.cs
  10. +4 −4 examples/C#/rtdealer.cs
  11. +2 −2 examples/C#/rtmama.cs
  12. +3 −3 examples/C#/rtpapa.cs
  13. +3 −3 examples/C++/identity.cpp
  14. +2 −2 examples/C++/lruqueue.cpp
  15. +1 −1 examples/C++/mdbroker.cpp
  16. +1 −1 examples/C++/mdcliapi2.hpp
  17. +1 −1 examples/C++/mdwrkapi.hpp
  18. +2 −2 examples/C++/msgqueue.cpp
  19. +2 −2 examples/C++/mtserver.cpp
  20. +2 −2 examples/C++/ppqueue.cpp
  21. +1 −1 examples/C++/ppworker.cpp
  22. +2 −2 examples/C++/rrbroker.cpp
  23. +4 −4 examples/C++/rtdealer.cpp
  24. +2 −2 examples/C++/rtmama.cpp
  25. +3 −3 examples/C++/rtpapa.cpp
  26. +2 −2 examples/C++/spqueue.cpp
  27. +4 −4 examples/C++/tripping.cpp
  28. +2 −2 examples/C++/zmsg.hpp
  29. +1 −1 examples/C/rtdealer.c
  30. +2 −2 examples/C/zhelpers.h
  31. +3 −3 examples/CL/identity.lisp
  32. +2 −2 examples/CL/lruqueue.lisp
  33. +2 −2 examples/CL/msgqueue.lisp
  34. +2 −2 examples/CL/mtserver.lisp
  35. +2 −2 examples/CL/rrbroker.lisp
  36. +2 −2 examples/CL/rtdealer.asd
  37. +4 −4 examples/CL/rtdealer.lisp
  38. +2 −2 examples/CL/rtmama.asd
  39. +2 −2 examples/CL/rtmama.lisp
  40. +2 −2 examples/CL/rtpapa.asd
  41. +3 −3 examples/CL/rtpapa.lisp
  42. +2 −2 examples/CL/rtrouter.asd
  43. +3 −3 examples/CL/rtrouter.lisp
  44. +2 −2 examples/CL/zmsg.lisp
  45. +1 −1 examples/Clojure/identity.clj
  46. +2 −2 examples/Clojure/rrbroker.clj
  47. +2 −2 examples/Clojure/rtdealer.clj
  48. +1 −1 examples/Erlang/rtdealer.es
  49. +1 −1 examples/F#/rtdealer.fsx
  50. +2 −2 examples/Haskell/msgqueue.hs
  51. +2 −2 examples/Haskell/mtserver.hs
  52. +2 −2 examples/Haskell/rrbroker.hs
  53. +1 −1 examples/Haxe/rtdealer.hx
  54. +2 −2 examples/Java/lruqueue.java
  55. +2 −2 examples/Java/msgqueue.java
  56. +2 −2 examples/Java/ppqueue.java
  57. +1 −1 examples/Java/ppworker.java
  58. +2 −2 examples/Java/rrbroker.java
  59. +5 −5 examples/Java/rtdealer.java
  60. +2 −2 examples/Java/spqueue.java
  61. +6 −6 examples/Lua/asyncsrv.lua
  62. +2 −2 examples/Lua/flserver3.lua
  63. +3 −3 examples/Lua/identity.lua
  64. +2 −2 examples/Lua/lruqueue.lua
  65. +2 −2 examples/Lua/lruqueue2.lua
  66. +1 −1 examples/Lua/mdbroker.lua
  67. +1 −1 examples/Lua/mdcliapi2.lua
  68. +1 −1 examples/Lua/mdwrkapi.lua
  69. +2 −2 examples/Lua/msgqueue.lua
  70. +2 −2 examples/Lua/mtserver.lua
  71. +4 −4 examples/Lua/peering2.lua
  72. +4 −4 examples/Lua/peering3.lua
  73. +2 −2 examples/Lua/ppqueue.lua
  74. +1 −1 examples/Lua/ppworker.lua
  75. +2 −2 examples/Lua/rrbroker.lua
  76. +4 −4 examples/Lua/rtdealer.lua
  77. +2 −2 examples/Lua/rtmama.lua
  78. +3 −3 examples/Lua/rtpapa.lua
  79. +3 −3 examples/Lua/rtrouter.lua
  80. +2 −2 examples/Lua/spqueue.lua
  81. +4 −4 examples/Lua/tripping.lua
  82. +2 −2 examples/Lua/zmsg_test.lua
  83. +6 −6 examples/PHP/asyncsrv.php
  84. +3 −3 examples/PHP/identity.php
  85. +2 −2 examples/PHP/lruqueue.php
  86. +2 −2 examples/PHP/lruqueue2.php
  87. +1 −1 examples/PHP/mdbroker.php
  88. +1 −1 examples/PHP/mdcliapi2.php
  89. +1 −1 examples/PHP/mdwrkapi.php
  90. +2 −2 examples/PHP/msgqueue.php
  91. +2 −2 examples/PHP/mtserver.php
  92. +4 −4 examples/PHP/peering2.php
  93. +4 −4 examples/PHP/peering3.php
  94. +2 −2 examples/PHP/ppqueue.php
  95. +1 −1 examples/PHP/ppworker.php
  96. +2 −2 examples/PHP/rrbroker.php
  97. +4 −4 examples/PHP/rtdealer.php
  98. +2 −2 examples/PHP/rtmama.php
  99. +3 −3 examples/PHP/rtpapa.php
  100. +3 −3 examples/PHP/rtrouter.php
  101. +2 −2 examples/PHP/spqueue.php
  102. +4 −4 examples/PHP/tripping.php
  103. +2 −2 examples/PHP/zmsg.php
  104. +2 −2 examples/Perl/msgqueue.pl
  105. +2 −2 examples/Perl/mtserver.pl
  106. +2 −2 examples/Perl/rrbroker.pl
  107. +4 −4 examples/Python/asyncsrv.py
  108. +1 −1 examples/Python/flclient2.py
  109. +4 −4 examples/Python/identity.py
  110. +2 −2 examples/Python/lruqueue.py
  111. +2 −2 examples/Python/lruqueue2.py
  112. +2 −2 examples/Python/lruqueue3.py
  113. +2 −2 examples/Python/msgqueue.py
  114. +2 −2 examples/Python/mtserver.py
  115. +2 −2 examples/Python/ppqueue.py
  116. +1 −1 examples/Python/ppworker.py
  117. +2 −2 examples/Python/rrbroker.py
  118. +4 −4 examples/Python/rtdealer.py
  119. +2 −2 examples/Python/rtmama.py
  120. +3 −3 examples/Python/rtpapa.py
  121. +3 −3 examples/Python/rtrouter.py
  122. +2 −2 examples/Python/spqueue.py
  123. +2 −2 examples/Python/zhelpers.py
  124. +2 −2 examples/Ruby/identity.rb
  125. +2 −2 examples/Ruby/msgqueue.rb
  126. +2 −2 examples/Ruby/rrbroker.rb
  127. +1 −1 examples/Ruby/rtdealer.rb
  128. +1 −1 examples/Scala/rtdealer.scala
@@ -481,9 +481,9 @@ zmsg_test (int verbose)
// Prepare our context and sockets
void *context = zmq_init (1);
- void *output = zmq_socket (context, ZMQ_XREQ);
+ void *output = zmq_socket (context, ZMQ_DEALER);
assert (zmq_bind (output, "ipc://zmsg_selftest.ipc") == 0);
- void *input = zmq_socket (context, ZMQ_XREP);
+ void *input = zmq_socket (context, ZMQ_ROUTER);
assert (zmq_connect (input, "ipc://zmsg_selftest.ipc") == 0);
// Test send and receive of single-part message
@@ -37,11 +37,11 @@ begin
ctx.Initialize (servers'Length + 1);
-- Create a ZMQ_REP socket to receive requests and send replies
- workers.Initialize (ctx, Sockets.XREQ);
+ workers.Initialize (ctx, Sockets.DEALER);
workers.Bind ("inproc://workers");
-- Bind to the TCP transport and port 5555 on the 'lo' interface
- clients.Initialize (ctx, Sockets.XREP);
+ clients.Initialize (ctx, Sockets.ROUTER);
clients.Bind ("tcp://lo:5555");
for i in servers'Range loop
@@ -1,5 +1,5 @@
//
-// Asynchronous client-to-server (XREQ to XREP)
+// Asynchronous client-to-server (DEALER to ROUTER)
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each task has its own
@@ -24,7 +24,7 @@ class Program {
// run several client tasks in parallel, each with a different random ID.
static void ClientTask() {
using (Context ctx = new Context(1)) {
- using (Socket client = ctx.Socket(SocketType.XREQ)) {
+ using (Socket client = ctx.Socket(SocketType.DEALER)) {
// Generate printable identity for the client
ZHelpers.SetID(client, Encoding.Unicode);
string identity = client.IdentityToString(Encoding.Unicode);
@@ -58,8 +58,8 @@ class Program {
static void ServerTask() {
List<Thread> workers = new List<Thread>(5);
using (Context ctx = new Context(1)) {
- using (Socket frontend = ctx.Socket(SocketType.XREP),
- backend = ctx.Socket(SocketType.XREQ)) {
+ using (Socket frontend = ctx.Socket(SocketType.ROUTER),
+ backend = ctx.Socket(SocketType.DEALER)) {
// Frontend socket talks to clients over TCP
frontend.Bind("tcp://*:5570");
// Backend socket talks to workers over inproc
@@ -101,10 +101,10 @@ class Program {
//
static void ServerWorker(object ctx) {
Random rand = new Random(DateTime.Now.Millisecond);
- using (Socket worker = ((Context)ctx).Socket(SocketType.XREQ)) {
+ using (Socket worker = ((Context)ctx).Socket(SocketType.DEALER)) {
worker.Connect("inproc://backend");
while (true) {
- // The XREQ socket gives us the address envelope and message
+ // The DEALER socket gives us the address envelope and message
ZMessage zmsg = new ZMessage(worker);
// Send 0..4 replies back
int replies = rand.Next(5);
@@ -13,21 +13,21 @@ namespace identity {
class Program {
static void Main(string[] args) {
using (Context ctx = new Context()) {
- using (Socket sink = ctx.Socket(SocketType.XREP),
+ using (Socket sink = ctx.Socket(SocketType.ROUTER),
anonymous = ctx.Socket(SocketType.REQ),
identified = ctx.Socket(SocketType.REQ)) {
sink.Bind("inproc://example");
// First allow 0MQ to set the identity
anonymous.Connect("inproc://example");
- anonymous.Send("XREP uses a generated UUID", Encoding.Unicode);
+ anonymous.Send("ROUTER uses a generated UUID", Encoding.Unicode);
ZHelpers.Dump(sink, Encoding.Unicode);
// Then set the identity ourself
identified.StringToIdentity("Hello", Encoding.Unicode);
identified.Connect("inproc://example");
- identified.Send("XREP socket uses REQ's socket identity", Encoding.Unicode);
+ identified.Send("ROUTER socket uses REQ's socket identity", Encoding.Unicode);
ZHelpers.Dump(sink, Encoding.Unicode);
}
}
@@ -69,8 +69,8 @@ class Program {
List<Thread> clients = new List<Thread>();
// Prepare our context and sockets
using (Context ctx = new Context(1)) {
- using (Socket frontend = ctx.Socket(SocketType.XREP),
- backend = ctx.Socket(SocketType.XREP)) {
+ using (Socket frontend = ctx.Socket(SocketType.ROUTER),
+ backend = ctx.Socket(SocketType.ROUTER)) {
frontend.Bind("tcp://*:5555");
backend.Bind("tcp://*:5556");
@@ -66,8 +66,8 @@ class Program {
// Prepare our context and sockets
using (Context ctx = new Context(1)) {
- using (Socket frontend = ctx.Socket(SocketType.XREP),
- backend = ctx.Socket(SocketType.XREP)) {
+ using (Socket frontend = ctx.Socket(SocketType.ROUTER),
+ backend = ctx.Socket(SocketType.ROUTER)) {
frontend.Bind("tcp://*:5555");
backend.Bind("tcp://*:5556");
@@ -14,8 +14,8 @@ namespace ZMQGuide {
class Program {
static void Main(string[] args) {
using (Context context = new Context(1)) {
- using (Socket frontend = context.Socket(SocketType.XREP),
- backend = context.Socket(SocketType.XREQ)) {
+ using (Socket frontend = context.Socket(SocketType.ROUTER),
+ backend = context.Socket(SocketType.DEALER)) {
// Socket facing clients
frontend.Bind("tcp://*:5559");
// Socket facing services
@@ -28,8 +28,8 @@ class Program {
static void Main(string[] args) {
using (Context context = new Context(1)) {
- using (Socket clients = context.Socket(SocketType.XREP),
- workers = context.Socket(SocketType.XREQ)) {
+ using (Socket clients = context.Socket(SocketType.ROUTER),
+ workers = context.Socket(SocketType.DEALER)) {
// Socket to talk to clients
clients.Bind("tcp://*:5555");
// Socket to talk to workers
@@ -18,8 +18,8 @@ public class RRBroker {
public RRBroker() {
// Prepare our context and sockets
context = new Context(1);
- frontend = context.Socket(SocketType.XREP);
- backend = context.Socket(SocketType.XREQ);
+ frontend = context.Socket(SocketType.ROUTER);
+ backend = context.Socket(SocketType.DEALER);
frontend.Bind("tcp://*:5559");
backend.Bind("tcp://*:5560");
}
@@ -1,5 +1,5 @@
//
-// Custom routing Router to Dealer (XREP to XREQ)
+// Custom routing Router to Dealer
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each thread has its own
@@ -22,7 +22,7 @@ class Program {
//
static void WorkerTaskA() {
using (Context ctx = new Context(1)) {
- using (Socket worker = ctx.Socket(SocketType.XREQ)) {
+ using (Socket worker = ctx.Socket(SocketType.DEALER)) {
worker.StringToIdentity("A", Encoding.Unicode);
worker.Connect("tcp://localhost:5555");
int total = 0;
@@ -40,7 +40,7 @@ class Program {
static void WorkerTaskB() {
using (Context ctx = new Context(1)) {
- using (Socket worker = ctx.Socket(SocketType.XREQ)) {
+ using (Socket worker = ctx.Socket(SocketType.DEALER)) {
worker.StringToIdentity("B", Encoding.Unicode);
worker.Connect("tcp://localhost:5555");
int total = 0;
@@ -61,7 +61,7 @@ class Program {
List<Thread> workers = new List<Thread>(new Thread[] {
new Thread(WorkerTaskA), new Thread(WorkerTaskB) });
using (Context ctx = new Context(1)) {
- using (Socket client = ctx.Socket(SocketType.XREP)) {
+ using (Socket client = ctx.Socket(SocketType.ROUTER)) {
client.Bind("tcp://*:5555");
foreach (Thread thread in workers) {
thread.Start();
@@ -1,5 +1,5 @@
//
-// Custom routing Router to Mama (XREP to REQ)
+// Custom routing Router to Mama (ROUTER to REQ)
//
// While this example runs in a single process, that is just to make
// it easier to start and stop the example. Each thread has its own
@@ -50,7 +50,7 @@ class Program {
ZHelpers.VersionAssert(2, 1);
List<Thread> workers = new List<Thread>(NBR_WORKERS);
using (Context ctx = new Context(1)) {
- using (Socket client = ctx.Socket(SocketType.XREP)) {
+ using (Socket client = ctx.Socket(SocketType.ROUTER)) {
client.Bind("tcp://*:5555");
for (int workerNbr = 0; workerNbr < NBR_WORKERS; workerNbr++) {
workers.Add(new Thread(WorkerTask));
@@ -1,5 +1,5 @@
//
-// Custom routing Router to Papa (XREP to REP)
+// Custom routing Router to Papa (ROUTER to REP)
//
// Author: Michael Compton
@@ -17,7 +17,7 @@ class Program {
// of events...
static void Main(string[] args) {
using (Context ctx = new Context(1)) {
- using (Socket client = ctx.Socket(SocketType.XREP),
+ using (Socket client = ctx.Socket(SocketType.ROUTER),
worker = ctx.Socket(SocketType.REP)) {
client.Bind("inproc://routing");
@@ -42,7 +42,7 @@ class Program {
// We don't play with envelopes in the worker
worker.Send("This is the reply", Encoding.Unicode);
- // Now dump what we got off the XREP socket...
+ // Now dump what we got off the ROUTER socket...
ZHelpers.Dump(client, Encoding.Unicode);
}
}
@@ -10,22 +10,22 @@
int main () {
zmq::context_t context(1);
- zmq::socket_t sink(context, ZMQ_XREP);
+ zmq::socket_t sink(context, ZMQ_ROUTER);
sink.bind( "inproc://example");
// First allow 0MQ to set the identity
zmq::socket_t anonymous(context, ZMQ_REQ);
anonymous.connect( "inproc://example");
- s_send (anonymous, "XREP uses a generated UUID");
+ s_send (anonymous, "ROUTER uses a generated UUID");
s_dump (sink);
// Then set the identity ourself
zmq::socket_t identified (context, ZMQ_REQ);
identified.setsockopt( ZMQ_IDENTITY, "Hello", 5);
identified.connect( "inproc://example");
- s_send (identified, "XREP socket uses REQ's socket identity");
+ s_send (identified, "ROUTER socket uses REQ's socket identity");
s_dump (sink);
return 0;
@@ -61,8 +61,8 @@ int main (int argc, char *argv[])
// Prepare our context and sockets
zmq::context_t context(1);
- zmq::socket_t frontend (context, ZMQ_XREP);
- zmq::socket_t backend (context, ZMQ_XREP);
+ zmq::socket_t frontend (context, ZMQ_ROUTER);
+ zmq::socket_t backend (context, ZMQ_ROUTER);
frontend.bind("ipc://frontend.ipc");
backend.bind("ipc://backend.ipc");
@@ -100,7 +100,7 @@ class broker {
{
// Initialize broker state
m_context = new zmq::context_t(1);
- m_socket = new zmq::socket_t(*m_context, ZMQ_XREP);
+ m_socket = new zmq::socket_t(*m_context, ZMQ_ROUTER);
m_verbose = verbose;
m_heartbeat_at = s_clock () + HEARTBEAT_INTERVAL;
}
@@ -77,7 +77,7 @@ class mdcli {
if (m_client) {
delete m_client;
}
- m_client = new zmq::socket_t (*m_context, ZMQ_XREQ);
+ m_client = new zmq::socket_t (*m_context, ZMQ_DEALER);
int linger = 0;
m_client->setsockopt (ZMQ_LINGER, &linger, sizeof (linger));
m_client->connect (m_broker.c_str());
@@ -104,7 +104,7 @@ class mdwrk {
if (m_worker) {
delete m_worker;
}
- m_worker = new zmq::socket_t (*m_context, ZMQ_XREQ);
+ m_worker = new zmq::socket_t (*m_context, ZMQ_DEALER);
int linger = 0;
m_worker->setsockopt (ZMQ_LINGER, &linger, sizeof (linger));
m_worker->connect (m_broker.c_str());
@@ -12,11 +12,11 @@ int main (int argc, char *argv[])
zmq::context_t context(1);
// Socket facing clients
- zmq::socket_t frontend (context, ZMQ_XREP);
+ zmq::socket_t frontend (context, ZMQ_ROUTER);
frontend.bind("tcp://*:5559");
// Socket facing services
- zmq::socket_t backend (context, ZMQ_XREQ);
+ zmq::socket_t backend (context, ZMQ_DEALER);
zmq_bind (backend, "tcp://*:5560");
// Start built-in device
@@ -38,9 +38,9 @@ int main ()
{
// Prepare our context and sockets
zmq::context_t context (1);
- zmq::socket_t clients (context, ZMQ_XREP);
+ zmq::socket_t clients (context, ZMQ_ROUTER);
clients.bind ("tcp://*:5555");
- zmq::socket_t workers (context, ZMQ_XREQ);
+ zmq::socket_t workers (context, ZMQ_DEALER);
workers.bind ("inproc://workers");
// Launch pool of worker threads
@@ -97,8 +97,8 @@ int main (void)
// Prepare our context and sockets
zmq::context_t context(1);
- zmq::socket_t frontend(context, ZMQ_XREP);
- zmq::socket_t backend (context, ZMQ_XREP);
+ zmq::socket_t frontend(context, ZMQ_ROUTER);
+ zmq::socket_t backend (context, ZMQ_ROUTER);
frontend.bind("tcp://*:5555"); // For clients
backend.bind ("tcp://*:5556"); // For workers
@@ -20,7 +20,7 @@ std::string identity;
static zmq::socket_t *
s_worker_socket (zmq::context_t &context) {
- zmq::socket_t * worker = new zmq::socket_t(context, ZMQ_XREQ);
+ zmq::socket_t * worker = new zmq::socket_t(context, ZMQ_DEALER);
// Set random identity to make tracing easier
identity = s_set_id(*worker);
@@ -11,8 +11,8 @@ int main (int argc, char *argv[])
{
// Prepare our context and sockets
zmq::context_t context(1);
- zmq::socket_t frontend (context, ZMQ_XREP);
- zmq::socket_t backend (context, ZMQ_XREQ);
+ zmq::socket_t frontend (context, ZMQ_ROUTER);
+ zmq::socket_t backend (context, ZMQ_DEALER);
frontend.bind("tcp://*:5559");
backend.bind("tcp://*:5560");
@@ -1,5 +1,5 @@
//
-// Custom routing Router to Dealer (XREP to XREQ)
+// Custom routing Router to Dealer
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>
@@ -11,7 +11,7 @@
void *worker_a (void *arg) {
zmq::context_t * context = (zmq::context_t *)arg;
- zmq::socket_t worker (*context, ZMQ_XREQ);
+ zmq::socket_t worker (*context, ZMQ_DEALER);
worker.setsockopt( ZMQ_IDENTITY, "A", 1);
worker.connect("ipc://routing.ipc");
@@ -32,7 +32,7 @@ void *worker_a (void *arg) {
void *worker_b (void *arg) {
zmq::context_t * context = (zmq::context_t *)arg;
- zmq::socket_t worker (*context, ZMQ_XREQ);
+ zmq::socket_t worker (*context, ZMQ_DEALER);
worker.setsockopt( ZMQ_IDENTITY, "B", 1);
worker.connect("ipc://routing.ipc");
@@ -54,7 +54,7 @@ int main () {
zmq::context_t context(1);
- zmq::socket_t client (context, ZMQ_XREP);
+ zmq::socket_t client (context, ZMQ_ROUTER);
client.bind("ipc://routing.ipc");
pthread_t worker;
@@ -1,5 +1,5 @@
//
-// Custom routing Router to Mama (XREP to REQ)
+// Custom routing Router to Mama (ROUTER to REQ)
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>
@@ -40,7 +40,7 @@ worker_thread (void *arg) {
int main () {
zmq::context_t context(1);
- zmq::socket_t client (context, ZMQ_XREP);
+ zmq::socket_t client (context, ZMQ_ROUTER);
client.bind("ipc://routing.ipc");
int worker_nbr;
Oops, something went wrong. Retry.

0 comments on commit 49975cf

Please sign in to comment.