Ejemplo n.º 1
0
        private static void Main()
        {
            Console.Title = "NetMQ Multi-threaded Service";

            var queue = new QueueDevice("tcp://localhost:5555", "tcp://localhost:5556", DeviceMode.Threaded);

            var source = new CancellationTokenSource();
            s_token = source.Token;

            for (int threadId = 0; threadId < 10; threadId++)
                Task.Factory.StartNew(WorkerRoutine, s_token);

            queue.Start();

            var clientThreads = new List<Task>();
            for (int threadId = 0; threadId < 1000; threadId++)
            {
                int id = threadId;
                clientThreads.Add(Task.Factory.StartNew(() => ClientRoutine(id)));
            }

            Task.WaitAll(clientThreads.ToArray());

            source.Cancel();

            queue.Stop();

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
       public void CallMethod_Using_NProxyWrapper_ReadMessageWithRawActor()
       {
            waitHandle.Reset();
            using (var context = NetMQContext.Create())
            {
                using (var exchange = new Exchange(context))
                {
                    exchange.Start();
                    
                    var queueDevice = new QueueDevice(
                    context,
                    Pipe.PubSubControlBackAddressServer,
                    Pipe.PubSubControlFrontAddressServer,
                    DeviceMode.Threaded);
                    queueDevice.Start();

                    Thread.Sleep(200);

                    var task = Task.Run(() =>
                    {
                        return RunSubscriber(context);
                    });

                    using (var actor = new Actor(context, new BinarySerializer()))
                    {
                        using (var syncService = context.CreateResponseSocket())
                        {
                            syncService.Connect(Pipe.PubSubControlFrontAddressClient);
                            for (int i = 0; i < 1; i++)
                            {
                                syncService.Receive();
                                syncService.Send(string.Empty);
                            }

                            var order = actor.CreateInstance<IOrder>(typeof(Order));
                            Assert.IsInstanceOfType(order, typeof(IOrder));
                            order.UpdateDescription("XXX"); //called without exception    
                            waitHandle.WaitOne();

                            var netMqMessage = new NetMQMessage();
                            netMqMessage.Append(new NetMQFrame(string.Empty));
                            netMqMessage.Append(new NetMQFrame("shutdownallactors"));
                            actor.OutputChannel.SendMessage(netMqMessage);

                            //actor.SendKillSignal(actor.Serializer, actor.OutputChannel, string.Empty);
                        }
                    }

                    Thread.Sleep(200);

                    queueDevice.Stop(true);
                    exchange.Stop(true);
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                //var queue = new QueueDevice(context, "tcp://localhost:5555", "inproc://workers", DeviceMode.Threaded);
                var queue = new QueueDevice(context, "tcp://localhost:5555", "tcp://localhost:5556", DeviceMode.Threaded);

                CancellationTokenSource source = new CancellationTokenSource();
                token = source.Token;

                List<Task> workerThreads = new List<Task>();
                for (int threadId = 0; threadId < 10; threadId++)
                {
                    NetMQContext ctx = context;
                    workerThreads.Add(Task.Factory.StartNew(() => WorkerRoutine(new Worker(Guid.NewGuid(), ctx)), token));
                }

                queue.Start();

                List<Task> clientThreads = new List<Task>();
                for (int threadId = 0; threadId < 1000; threadId++)
                {
                    int id = threadId;
                    clientThreads.Add(Task.Factory.StartNew(() => ClientRoutine(id)));
                }

                Task.WaitAll(clientThreads.ToArray());

                source.Cancel();

                queue.Stop();
            }

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }