コード例 #1
0
        public async void SubscriberGetsEventContextWithPublicationId(bool?acknowledge)
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisher  = dualChannel.Publisher;
            IWampChannel subscriber = dualChannel.Subscriber;

            MyOtherSubscriber mySubscriber = new MyOtherSubscriber();

            IAsyncDisposable disposable =
                await subscriber.RealmProxy.Services.RegisterSubscriber
                    (mySubscriber);

            IWampTopicProxy topicProxy =
                publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2");

            long?publish =
                await topicProxy.Publish
                    (new PublishOptions { Acknowledge = acknowledge },
                    new object[] { 47, 23, "Hello" });

            if (acknowledge == true)
            {
                Assert.That(publish, Is.EqualTo(mySubscriber.EventContext.PublicationId));
            }
            else
            {
                Assert.That(mySubscriber.EventContext.PublicationId, Is.Not.Null);
            }
        }
コード例 #2
0
        public async Task SubscriberGetsEventContextWithPublisherId(bool?discloseMe)
        {
            WampPlayground playground = new WampPlayground();

            PublisherSubscriber dualChannel = await playground.GetPublisherSubscriberDualChannel();

            IWampChannel publisher  = dualChannel.Publisher;
            IWampChannel subscriber = dualChannel.Subscriber;

            MyOtherSubscriber mySubscriber = new MyOtherSubscriber();

            IAsyncDisposable disposable =
                await subscriber.RealmProxy.Services.RegisterSubscriber
                    (mySubscriber);

            IWampTopicProxy topicProxy =
                publisher.RealmProxy.TopicContainer.GetTopicByUri("com.myapp.mytopic2");

            long?publish =
                await topicProxy.Publish
                    (new PublishOptions { DiscloseMe = discloseMe },
                    new object[] { 47, 23, "Hello" });

            long?publisherId = mySubscriber.EventContext.EventDetails.Publisher;

            if (discloseMe == true)
            {
                Assert.That(publisherId, Is.EqualTo(dualChannel.PublisherSessionId));
            }
            else
            {
                Assert.That(publisherId, Is.EqualTo(null));
            }
        }
コード例 #3
0
        public async Task SubscriberGetsRetainedEvent(bool?publishRetained, bool?getRetained, int expectedCount, bool?acknowledge = null)
        {
            WampPlayground playground = new WampPlayground();

            playground.Host.Open();

            ChannelWithExtraData publisher = await playground.GetChannel().ConfigureAwait(false);

            ChannelWithExtraData subscriber = await playground.GetChannel().ConfigureAwait(false);

            IWampTopicProxy topicProxy =
                publisher.Channel.RealmProxy.TopicContainer.GetTopicByUri
                    ("com.myapp.mytopic2");

            long?lastPublicationId = null;

            for (int i = 0; i <= 42; i++)
            {
                lastPublicationId =
                    await topicProxy.Publish
                        (new PublishOptions
                {
                    Retain      = publishRetained,
                    Acknowledge = acknowledge
                },
                        new object[] { i, 23, "Hello" });
            }

            publisher.Channel.Close();

            MyOtherSubscriber mySubscriber = new MyOtherSubscriber();

            IAsyncDisposable disposable =
                await subscriber.Channel.RealmProxy.Services.RegisterSubscriber(mySubscriber,
                                                                                new SubscriberRegistrationInterceptor(new SubscribeOptions()
            {
                GetRetained = getRetained
            }))
                .ConfigureAwait(false);

            Assert.That(mySubscriber.Parameters.Count, Is.EqualTo(expectedCount));

            if (expectedCount == 1)
            {
                MyTopic2Parameters actual = mySubscriber.Parameters[0];
                Assert.That(actual.Number1, Is.EqualTo(42));
                Assert.That(actual.Number2, Is.EqualTo(23));
                Assert.That(actual.C, Is.EqualTo("Hello"));
                Assert.That(actual.EventContext.EventDetails.Retained, Is.EqualTo(true));

                if (acknowledge == true)
                {
                    Assert.That(actual.EventContext.PublicationId, Is.EqualTo(lastPublicationId));
                }
            }
        }