Esempio n. 1
0
        public void ExchangeTest()
        {
            using (var context = NetMQContext.Create())
            {
                var exchange = new XForwarder(
                    context,
                    Pipe.PublishAddressServer,
                    Pipe.SubscribeAddressServer,
                    DeviceMode.Threaded);
                //exchange.FrontendSetup.Subscribe("");
               // exchange.BackendSetup.Subscribe("");
                exchange.Start();
                var pub = Helper.GetConnectedPublishSocket(context, Pipe.PublishAddressClient);
                var sub = Helper.GetConnectedSubscribeSocket(context, Pipe.SubscribeAddressClient);
                var sub2 = Helper.GetConnectedSubscribeSocket(context, Pipe.SubscribeAddressClient);
                var sub3 = Helper.GetConnectedSubscribeSocket(context, Pipe.SubscribeAddressClient, "hello");
                var sub4 = Helper.GetConnectedSubscribeSocket(context, Pipe.SubscribeAddressClient, "Nothello");

                sub.ReceiveReady +=sub_ReceiveReady;

                Thread.Sleep(100);
                //while (!ReceiveReady)
                //{

                //}

                pub.Send("hello");
                var received = sub.ReceiveString();
                Assert.AreEqual("hello", received);
                var received2 = sub2.ReceiveString();
                Assert.AreEqual("hello", received2);

                var received3 = sub3.ReceiveString();
                Assert.AreEqual("hello", received3);

                pub.Send("Nothello");
                var received4 = sub4.ReceiveString();
                Assert.AreEqual("Nothello", received4);

                exchange.Stop(true);

                pub.Dispose();
                sub.Dispose();
                sub2.Dispose();
                sub3.Dispose();
                sub4.Dispose();
            }
        }
Esempio n. 2
0
        public void CallMethod_Multiple_ObjectsBinarySerializer()
        {
            using (var context = NetMQContext.Create())
            {
                var exchange = new XForwarder(context, Pipe.SubscribeAddress, Pipe.PublishAddress, DeviceMode.Threaded);
                exchange.Start();

                using (var actor = new Actor<Customer>(context, new BinarySerializer()))
                {
                    var customer = actor.CreateInstance<ICustomer>(typeof(Customer), 33);
                    Assert.IsInstanceOfType(customer, typeof(ICustomer));
                    customer.UpdateName("XXX"); //called without exception

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

                    var order2 = actor.CreateInstance<IOrder>(typeof(Order), Guid.NewGuid());
                    Assert.IsInstanceOfType(order2, typeof(IOrder));
                    order2.UpdateDescription("ZZZ"); //called without exception
                }

                exchange.Stop();
            }
        }