0

I facing some problems with the example I got from the ZeroMQ Guide, looks like the class ZSocket and ZContext doesn't exist. I'm totally new with ZeroMQ (just start lo learn) and I'm following the "ØMQ - The Guide". The first example about REQ-REP, which is very simple, worked well. But now I'm trying something more similar to my objective, the "Brokerless Reliability (Freelance Pattern)" and this one didn't work.

I'm using Visual Studio 2019 with C# code, I created a new project, added NetMQ V4.0.1.6 via Nuget and copied the server code to my project. I got errors with ZContext and ZSocket. I already check the API V3 and API V4, they are clear different. The guide is totally based on version 3 and I'm using V 4. I didn't find any document about the changes or updates or equivalent function/classes/methods and I don't know how to convert the example to the NetMQ V4.

This is my test code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using NetMQ;

namespace Examples
{
    static partial class Program
    {
        public static void FLServer1(string[] args)
        {
            //
            // Freelance server - Model 1
            // Trivial echo service
            //
            // Author: metadings
            //

            if (args == null || args.Length < 1)
            {
                Console.WriteLine();
                Console.WriteLine("Usage: ./{0} FLServer1 [Endpoint]", AppDomain.CurrentDomain.FriendlyName);
                Console.WriteLine();
                Console.WriteLine("    Endpoint  Where FLServer1 should bind on.");
                Console.WriteLine("              Default is tcp://127.0.0.1:7780");
                Console.WriteLine();
                args = new string[] { "tcp://127.0.0.1:7780" };
            }

            using (var context = new ZContext())
            using (var server = new ZSocket(context, ZSocketType.REP))
            {
                server.Bind(args[0]);

                Console.WriteLine("I: echo service is ready at {0}", args[0]);

                ZMessage message;
                ZError error;
                while (true)
                {
                    if (null != (message = server.ReceiveMessage(out error)))
                    {
                        using (message)
                        {
                            server.Send(message);
                        }
                    }
                    else
                    {
                        if (error == ZError.ETERM)
                            return; // Interrupted
                        throw new ZException(error);
                    }
                }
            }
        }
    }
}

1 Answers1

0

After long hours trying to understand that logic, I found a list of differences from ZeroMQ V3 and V4: https://github.com/zeromq/netmq/wiki/Migrating-to-v4

Also, accidentally I found the example I was looking for: https://github.com/NetMQ/Samples/tree/master/src/Brokerless%20Reliability%20(Freelance%20Pattern)/Model%20One