Exemple #1
0
        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                var receiverManager = new NetMQReceiverManager(context, "tcp://127.0.0.1:5557");
                var messageFactory = new MessageFactory();
                var messageHandler = RequestDispatcher.Create()
                                                      .Register<App2ComplementRequest, App2ComplementResponse>(request =>
                                                      {
                                                          Console.WriteLine("Received a {0} urgency request for a complement", request.Urgency.ToString());

                                                          if (request.Urgency == Urgency.Low)
                                                              return new App2ComplementResponse("You're hair looks nice today");
                                                          else if (request.Urgency == Urgency.Medium)
                                                              return new App2ComplementResponse("Hey, you're pretty excellent");
                                                          else
                                                              return new App2ComplementResponse("You are probably a better programmer than me");
                                                      });

                IServer server = new Server(receiverManager, messageFactory, messageHandler, "ExampleServer");

                var cancellationTokenSource = new CancellationTokenSource();

                Console.WriteLine("Starting App2 server...");

                server.Start(cancellationTokenSource.Token);

                Console.WriteLine("Server started, press enter to shutdown");

                Console.ReadLine();

                Console.WriteLine("Stopping server");
                cancellationTokenSource.Cancel();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                var receiverManager = new NetMQReceiverManager(context, "tcp://127.0.0.1:5556");
                var messageFactory = new MessageFactory();
                var messageHandler = RequestDispatcher.Create()
                                                      .Register<App1RandomNumberRequest, App1RandomNumberResponse>(request => {
                                                          Console.WriteLine("Received request for random number between {0} and {1}", request.MinBound, request.MaxBound);
                                                          var random = new Random();
                                                          return new App1RandomNumberResponse(random.Next(request.MinBound, request.MaxBound));
                                                      });

                IServer server = new Server(receiverManager, messageFactory, messageHandler, "ExampleServer");

                var cancellationTokenSource = new CancellationTokenSource();

                Console.WriteLine("Starting server...");

                server.Start(cancellationTokenSource.Token);

                Console.WriteLine("Server started, press enter to shutdown");

                Console.ReadLine();

                Console.WriteLine("Stopping server");
                cancellationTokenSource.Cancel();
            }
        }