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


C# MessageHandler.GetTestResults方法代码示例

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


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

示例1: TestRdyRedistribution

        private static List<TestResults> TestRdyRedistribution(
            bool rdyRedistributeOnIdle,
            int maxInFlight,
            TimeSpan rdyRedistributeInterval,
            TimeSpan lowRdyIdleTimeout,
            TimeSpan handlerSleepTime,
            TimeSpan sleepBeforeIdlePublish,
            TimeSpan testDuration,
            bool startWithInitialMessageOnIdleNsqd,
            int numberOfMessagesToSendOnIdleNsqd,
            int numberOfMessages
        )
        {
            string topicName = string.Format("test_rdy_redistribution_{0}", DateTime.Now.UnixNano());

            try
            {
                _nsqdHttpClient1.CreateTopic(topicName);
                _nsqdHttpClient2.CreateTopic(topicName);
                _nsqLookupdHttpClient.CreateTopic(topicName);

                Producer p1 = new Producer("127.0.0.1:4150");
                if (startWithInitialMessageOnIdleNsqd)
                {
                    p1.Publish(topicName, "initial");
                }

                Producer p2 = new Producer("127.0.0.1:5150");
                for (int i = 0; i < numberOfMessages; i++)
                {
                    p2.Publish(topicName, i.ToString());
                }

                Consumer c = new Consumer(
                    topicName,
                    "test-channel",
                    new TestConsoleLogger(),
                    new Config
                    {
                        MaxInFlight = maxInFlight,
                        LowRdyIdleTimeout = lowRdyIdleTimeout,
                        RDYRedistributeInterval = rdyRedistributeInterval,
                        RDYRedistributeOnIdle = rdyRedistributeOnIdle
                    }
                );
                var messageHandler = new MessageHandler(handlerSleepTime);
                c.AddHandler(messageHandler, threads: maxInFlight);
                c.ConnectToNsqLookupd("127.0.0.1:4161");

                Thread.Sleep(sleepBeforeIdlePublish);

                for (int i = 1; i <= numberOfMessagesToSendOnIdleNsqd; i++)
                {
                    p1.Publish(topicName, string.Format("{0} - snuck in!", i));
                }

                Thread.Sleep(testDuration - sleepBeforeIdlePublish);

                p1.Stop();
                p2.Stop();

                c.Stop();

                return messageHandler.GetTestResults();
            }
            finally
            {
                _nsqdHttpClient1.DeleteTopic(topicName);
                _nsqdHttpClient2.DeleteTopic(topicName);
                _nsqLookupdHttpClient.DeleteTopic(topicName);
            }
        }
开发者ID:yonglehou,项目名称:NsqSharp,代码行数:72,代码来源:ConsumerRdyRedistributionTest.cs


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