当前位置: 首页>>代码示例>>C#>>正文


C# Publisher.Broadcast方法代码示例

本文整理汇总了C#中Publisher.Broadcast方法的典型用法代码示例。如果您正苦于以下问题:C# Publisher.Broadcast方法的具体用法?C# Publisher.Broadcast怎么用?C# Publisher.Broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Publisher的用法示例。


在下文中一共展示了Publisher.Broadcast方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: One_Publisher_One_Subscriber_Batch_Broadcast

        public void One_Publisher_One_Subscriber_Batch_Broadcast()
        {
            using (var publisher = new Publisher())
            using (var subscriber = new Subscriber())
            {
                var endpoint = GetEndpoint();
                publisher.Bind(endpoint);
                subscriber.Connect(endpoint);

                Thread.Sleep(100);

                var counterSignal = new CounterSignal(NumberOfMessagesToReceive);
                subscriber.MessageReceived += (s, m) => counterSignal.Increment();

                var messageSent = new TestMessage();

                var batch = new List<TestMessage>();
                for (var i = 0; i < NumberOfMessagesToReceive; i++)
                    batch.Add(messageSent);

                var sw = Stopwatch.StartNew();
                publisher.Broadcast(batch);
                Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                sw.Stop();

                Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessagesToReceive, NumberOfMessagesToReceive / sw.Elapsed.TotalSeconds);
            }
        }
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:28,代码来源:PublisherSubscriberBenchmarks.cs

示例2: Subscribe_to_Publisher_twice_on_same_endpoint

        public void Subscribe_to_Publisher_twice_on_same_endpoint(RedFoxTransport transport)
        {
            for (var i = 0; i < 2; i++)
            {
                using (var publisher = new Publisher())
                using (var subscriber = new TestSubscriber())
                {
                    var endpoint = TestHelpers.CreateEndpointForTransport(transport);

                    publisher.Bind(endpoint);
                    subscriber.Connect(endpoint);

                    var broadcastedMessage = new TestMessage { Text = "Hello" };
                    publisher.Broadcast(broadcastedMessage);
                }
            }
        }
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:17,代码来源:PublisherSubscriberTests.cs

示例3: Subscribe_to_Publisher_receive_single_broadcasted_message

        public void Subscribe_to_Publisher_receive_single_broadcasted_message(RedFoxTransport transport)
        {
            using (var publisher = new Publisher())
            using (var subscriber = new TestSubscriber())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(transport);

                publisher.Bind(endpoint);
                subscriber.Connect(endpoint);

                Thread.Sleep(100);

                var broadcastedMessage = new TestMessage { Text = "Hello" };

                publisher.Broadcast(broadcastedMessage);

                Assert.AreEqual(broadcastedMessage, subscriber.TestMustReceiveMessageWithin(Timeout));
            }
        }
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:19,代码来源:PublisherSubscriberTests.cs

示例4: One_Publisher_Hundred_Subscribers_Single_Broadcasts

        public void One_Publisher_Hundred_Subscribers_Single_Broadcasts()
        {
            using (var publisher = new Publisher())
            {
                var endpoint = GetEndpoint();
                publisher.Bind(endpoint);

                var counterSignal = new CounterSignal(NumberOfMessagesToReceive);
                var subscribers = Enumerable.Range(1, 100).Select(i =>
                {
                    var sub = new Subscriber();
                    sub.MessageReceived += (s, m) => counterSignal.Increment();
                    sub.Connect(endpoint);
                    return sub;
                }).ToList();

                Thread.Sleep(100);

                var messageSent = new TestMessage();

                var sw = Stopwatch.StartNew();
                for (var i = 0; i < NumberOfMessagesToReceive / 100; i++)
                {
                    publisher.Broadcast(messageSent);
                }
                Assert.IsTrue(counterSignal.Wait(TimeOut), "Timeout waiting for message");
                sw.Stop();

                subscribers.ForEach(sub => sub.Dispose());

                Assert.Inconclusive("{0} elapsed reading {1} messages ({2:N0} per second)", sw.Elapsed, NumberOfMessagesToReceive, NumberOfMessagesToReceive / sw.Elapsed.TotalSeconds);
            }
        }
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:33,代码来源:PublisherSubscriberBenchmarks.cs

示例5: using

        public void one_subscriber_connects_to_one_publisher_receives_message_then_second_subscriber_connects_both_receive_message(RedFoxTransport transport)
        {
            using (var publisher = new Publisher())
            using (var subscriber1 = new TestSubscriber())
            using (var subscriber2 = new TestSubscriber())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(transport);

                publisher.Bind(endpoint);
                subscriber1.Connect(endpoint);

                Thread.Sleep(100);

                var broadcastMessage = new TestMessage { Text = "Hello" };
                publisher.Broadcast(broadcastMessage);

                Assert.AreEqual(broadcastMessage, subscriber1.TestMustReceiveMessageWithin(Timeout));

                subscriber2.Connect(endpoint);

                Thread.Sleep(100);

                publisher.Broadcast(broadcastMessage);

                Assert.AreEqual(broadcastMessage, subscriber1.TestMustReceiveMessageWithin(Timeout));
                Assert.AreEqual(broadcastMessage, subscriber2.TestMustReceiveMessageWithin(Timeout));
            }
        }
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:28,代码来源:PublisherSubscriberTests.cs


注:本文中的Publisher.Broadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。