Ejemplo n.º 1
0
        public void Unsubscribe()
        {
            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    int port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);

                    sub.Subscribe("A");

                    // let the subscriber connect to the publisher before sending a message
                    Thread.Sleep(500);

                    pub.SendMoreFrame("A").SendFrame("Hello");

                    CollectionAssert.AreEqual(new[] { "A", "Hello" }, sub.ReceiveMultipartStrings());

                    sub.Unsubscribe("A");

                    Thread.Sleep(500);

                    pub.SendMoreFrame("A").SendFrame("Hello again");

                    Assert.IsFalse(sub.TrySkipFrame());
                }
        }
Ejemplo n.º 2
0
        public void MultipleSubscribersOnDifferentTopics()
        {
            using (var pub = new PublisherSocket())
                using (var sub1 = new SubscriberSocket())
                    using (var sub2 = new SubscriberSocket())
                    {
                        var port = pub.BindRandomPort("tcp://127.0.0.1");

                        sub1.Connect("tcp://127.0.0.1:" + port);
                        sub2.Connect("tcp://127.0.0.1:" + port);

                        sub1.Subscribe("1");
                        sub1.Subscribe("1&2");

                        sub2.Subscribe("2");
                        sub2.Subscribe("1&2");

                        Thread.Sleep(500);

                        pub.SendMoreFrame("1").SendFrame("A");

                        CollectionAssert.AreEqual(new[] { "1", "A" }, sub1.ReceiveMultipartStrings());
                        Assert.IsFalse(sub2.TrySkipFrame());

                        pub.SendMoreFrame("2").SendFrame("B");

                        Assert.IsFalse(sub1.TrySkipFrame());
                        CollectionAssert.AreEqual(new[] { "2", "B" }, sub2.ReceiveMultipartStrings());

                        pub.SendMoreFrame("1&2").SendFrame("C");

                        CollectionAssert.AreEqual(new[] { "1&2", "C" }, sub1.ReceiveMultipartStrings());
                        CollectionAssert.AreEqual(new[] { "1&2", "C" }, sub2.ReceiveMultipartStrings());
                    }
        }
Ejemplo n.º 3
0
        public void NotSubscribed()
        {
            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    var port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);

                    // let the subscriber connect to the publisher before sending a message
                    Thread.Sleep(500);

                    pub.SendFrame("Hello");

                    Assert.IsFalse(sub.TrySkipFrame());
                }
        }
Ejemplo n.º 4
0
        public void ClearWelcomeMessage()
        {
            using (var pub = new XPublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    pub.Bind("inproc://welcome");
                    pub.SetWelcomeMessage("W");
                    pub.ClearWelcomeMessage();

                    sub.Subscribe("W");
                    sub.Connect("inproc://welcome");

                    var subscription = pub.ReceiveFrameBytes();

                    Assert.AreEqual(subscription[1], (byte)'W');

                    Assert.IsFalse(sub.TrySkipFrame());
                }
        }