Skip to content

Commit

Permalink
Merge pull request #150 from igorw/xreq-xrep
Browse files Browse the repository at this point in the history
Replace old XREP and XREQ examples with ROUTER and DEALER
  • Loading branch information
hintjens committed Jan 5, 2012
2 parents f5fe47b + 0746a13 commit 49975cf
Show file tree
Hide file tree
Showing 128 changed files with 294 additions and 294 deletions.
4 changes: 2 additions & 2 deletions articles/src/multithreading/zmsg.c
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/Ada/zmq-examples-multi_thread_server.adb
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions examples/C#/asyncsrv.cs
@@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/identity.cs
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/lruqueue.cs
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/lruqueue2.cs
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/msgqueue.cs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/mtserver.cs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/rrbroker.cs
Expand Up @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions examples/C#/rtdealer.cs
@@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions examples/C#/rtmama.cs
@@ -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
Expand Down Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions examples/C#/rtpapa.cs
@@ -1,5 +1,5 @@
//
// Custom routing Router to Papa (XREP to REP)
// Custom routing Router to Papa (ROUTER to REP)
//

// Author: Michael Compton
Expand All @@ -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");
Expand All @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/C++/identity.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/lruqueue.cpp
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion examples/C++/mdbroker.cpp
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/C++/mdcliapi2.hpp
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion examples/C++/mdwrkapi.hpp
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/msgqueue.cpp
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/mtserver.cpp
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/ppqueue.cpp
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/C++/ppworker.cpp
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/rrbroker.cpp
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions examples/C++/rtdealer.cpp
@@ -1,5 +1,5 @@
//
// Custom routing Router to Dealer (XREP to XREQ)
// Custom routing Router to Dealer
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>

Expand All @@ -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");

Expand All @@ -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");

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions examples/C++/rtmama.cpp
@@ -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>

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 49975cf

Please sign in to comment.