當前位置: 首頁>>代碼示例>>C#>>正文


C# BrokerRouterProxy.Create方法代碼示例

本文整理匯總了C#中BrokerRouterProxy.Create方法的典型用法代碼示例。如果您正苦於以下問題:C# BrokerRouterProxy.Create方法的具體用法?C# BrokerRouterProxy.Create怎麽用?C# BrokerRouterProxy.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BrokerRouterProxy的用法示例。


在下文中一共展示了BrokerRouterProxy.Create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata

        public async Task ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata(ErrorResponseCode code)
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy._cacheExpiration = new TimeSpan(10);
            var router = routerProxy.Create();

            int partitionId = 0;

            ProtocolGateway protocolGateway = new ProtocolGateway(router);
            var fetchRequest = new FetchRequest();
            bool sendExOnFirstTime = true;

            Func<Task<FetchResponse>> ShouldReturnErrorAndThenNoError = async () =>
            {
                Task.Delay(routerProxy._cacheExpiration).Wait();
                Task.Delay(1).Wait();
                if (sendExOnFirstTime)
                {
                    sendExOnFirstTime = false;
                    return new FetchResponse() { Error = (short)code };
                }
                return new FetchResponse() { Error = (short)ErrorResponseCode.NoError };
            };
            routerProxy.BrokerConn0.FetchResponseFunction = ShouldReturnErrorAndThenNoError;
            routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.DefaultMetadataResponse;

            await protocolGateway.SendProtocolRequest(fetchRequest, BrokerRouterProxy.TestTopic, partitionId);

            Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
            Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
        }
開發者ID:BDeus,項目名稱:KafkaNetClient,代碼行數:31,代碼來源:ProtocolGatewayTest.cs

示例2: CancellationShouldInterruptConsumption

        public void CancellationShouldInterruptConsumption()
        {
            var routerProxy = new BrokerRouterProxy(new MoqMockingKernel());
            routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };

            var router = routerProxy.Create();

            var options = CreateOptions(router);

            using (var consumer = new Consumer(options))
            {
                var tokenSrc = new CancellationTokenSource();

                var consumeTask = Task.Run(() => consumer.Consume(tokenSrc.Token).FirstOrDefault());

                //wait until the fake broker is running and requesting fetches
                TaskTest.WaitFor(() => routerProxy.BrokerConn0.FetchRequestCallCount > 10);

                tokenSrc.Cancel();

                Assert.That(
                    Assert.Throws<AggregateException>(consumeTask.Wait).InnerException,
                    Is.TypeOf<OperationCanceledException>());
            }
        }
開發者ID:jsifantu,項目名稱:kafka-net,代碼行數:25,代碼來源:ConsumerTests.cs

示例3: EmptyTopicMetadataShouldThrowException

        public void EmptyTopicMetadataShouldThrowException()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            var router = routerProxy.Create();
            var common = new CommonQueries(router);

            common.GetTopic("MissingTopic");
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:8,代碼來源:CommonQueriesTests.cs

示例4: GetTopicShouldReturnTopic

        public void GetTopicShouldReturnTopic()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            var router = routerProxy.Create();
            var common = new CommonQueries(router);

            var result = common.GetTopic(BrokerRouterProxy.TestTopic);
            Assert.That(result.Name, Is.EqualTo(BrokerRouterProxy.TestTopic));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:9,代碼來源:CommonQueriesTests.cs

示例5: ShouldThrowFormatExceptionWhenTopicIsInvalid

 public async Task ShouldThrowFormatExceptionWhenTopicIsInvalid()
 {
     var routerProxy = new BrokerRouterProxy(_kernel);
     var router = routerProxy.Create();
     string invalidTopic = " ";
     var fetchRequest = new FetchRequest();
     ProtocolGateway protocolGateway = new ProtocolGateway(router);
     await protocolGateway.SendProtocolRequest(fetchRequest, invalidTopic, 0);
 }
開發者ID:gigya,項目名稱:KafkaNetClient,代碼行數:9,代碼來源:ProtocolGatewayTest.cs

示例6: GetTopicOffsetShouldQueryEachBroker

        public void GetTopicOffsetShouldQueryEachBroker()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            var router = routerProxy.Create();
            var common = new CommonQueries(router);

            var result = common.GetTopicOffsetAsync(BrokerRouterProxy.TestTopic).Result;
            Assert.That(routerProxy.BrokerConn0.OffsetRequestCallCount, Is.EqualTo(1));
            Assert.That(routerProxy.BrokerConn1.OffsetRequestCallCount, Is.EqualTo(1));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:10,代碼來源:CommonQueriesTests.cs

示例7: BrokerRouteShouldCycleThroughEachBrokerUntilOneIsFound

        public void BrokerRouteShouldCycleThroughEachBrokerUntilOneIsFound()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy.BrokerConn0.MetadataResponseFunction = () => { throw new Exception("some error"); };
            var router = routerProxy.Create();

            var result = router.GetTopicMetadata(TestTopic);
            Assert.That(result, Is.Not.Null);
            Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(1));
            Assert.That(routerProxy.BrokerConn1.MetadataRequestCallCount, Is.EqualTo(1));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:11,代碼來源:BrokerRouterTests.cs

示例8: GetTopicOffsetShouldThrowAnyException

        public void GetTopicOffsetShouldThrowAnyException()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy.BrokerConn0.OffsetResponseFunction = () => { throw new ApplicationException("test 99"); };
            var router = routerProxy.Create();
            var common = new CommonQueries(router);

            common.GetTopicOffsetAsync(BrokerRouterProxy.TestTopic).ContinueWith(t =>
            {
                Assert.That(t.IsFaulted, Is.True);
                Assert.That(t.Exception.Flatten().ToString(), Is.StringContaining("test 99"));
            }).Wait();
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:13,代碼來源:CommonQueriesTests.cs

示例9: BrokerRouteShouldReturnTopicFromCache

        public void BrokerRouteShouldReturnTopicFromCache()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            var router = routerProxy.Create();

            var result1 = router.GetTopicMetadata(TestTopic);
            var result2 = router.GetTopicMetadata(TestTopic);

            Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(1));
            Assert.That(result1.Count, Is.EqualTo(1));
            Assert.That(result1[0].Name, Is.EqualTo(TestTopic));
            Assert.That(result2.Count, Is.EqualTo(1));
            Assert.That(result2[0].Name, Is.EqualTo(TestTopic));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:14,代碼來源:BrokerRouterTests.cs

示例10: ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata

        public async Task ShouldTryToRefreshMataDataIfCanRecoverByRefreshMetadata(ErrorResponseCode code)
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy._cacheExpiration = new TimeSpan(10);
            var router = routerProxy.Create();
            ProtocolGateway protocolGateway = new ProtocolGateway(router);

            routerProxy.BrokerConn0.FetchResponseFunction = FailedInFirstMessageError(code, routerProxy._cacheExpiration);
            routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers;

            await protocolGateway.SendProtocolRequest(new FetchRequest(), BrokerRouterProxy.TestTopic, _partitionId);

            Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
            Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
        }
開發者ID:gigya,項目名稱:KafkaNetClient,代碼行數:15,代碼來源:ProtocolGatewayTest.cs

示例11: ShouldTryToRefreshMataDataIfOnExceptions

        public async Task ShouldTryToRefreshMataDataIfOnExceptions(Type exceptionType)
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy._cacheExpiration = TimeSpan.FromMilliseconds(10);
            var router = routerProxy.Create();
            ProtocolGateway protocolGateway = new ProtocolGateway(router);

            routerProxy.BrokerConn0.FetchResponseFunction = FailedInFirstMessageException(exceptionType, routerProxy._cacheExpiration);
            routerProxy.BrokerConn0.MetadataResponseFunction = BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers;

            await protocolGateway.SendProtocolRequest(new FetchRequest(), BrokerRouterProxy.TestTopic, _partitionId);

            Assert.That(routerProxy.BrokerConn0.MetadataRequestCallCount, Is.EqualTo(2));
            Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.EqualTo(2));
        }
開發者ID:gigya,項目名稱:KafkaNetClient,代碼行數:15,代碼來源:ProtocolGatewayTest.cs

示例12: ConsumerShouldReturnOffset

        public void ConsumerShouldReturnOffset()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
            var router = routerProxy.Create();
            var options = CreateOptions(router);
            options.PartitionWhitelist = new List<int>();
            var consumer = new Consumer(options);

            var test = consumer.Consume().Take(1);
            while (consumer.ConsumerTaskCount <= 0)
            {
                Thread.Sleep(100);
            }

            Assert.That(consumer.ConsumerTaskCount, Is.EqualTo(2));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:17,代碼來源:ConsumerTests.cs

示例13: ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition

        public void ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition()
        {
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
            var router = routerProxy.Create();
            var options = CreateOptions(router);
            options.PartitionWhitelist = new List<int> { 0 };
            var consumer = new Consumer(options);

            var test = consumer.Consume().Take(1);
            while (consumer.ConsumerTaskCount <= 0)
            {
                Thread.Sleep(100);
            }

            Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.GreaterThanOrEqualTo(1));
            Assert.That(routerProxy.BrokerConn1.FetchRequestCallCount, Is.EqualTo(0));
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:18,代碼來源:ConsumerTests.cs

示例14: ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition

        public void ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition()
        {
            var routerProxy = new BrokerRouterProxy(new MoqMockingKernel());
            routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };
            var router = routerProxy.Create();
            var options = CreateOptions(router);
            options.PartitionWhitelist = new List<int> { 0 };
            using (var consumer = new Consumer(options))
            {
                var test = consumer.Consume();

                TaskTest.WaitFor(() => consumer.ConsumerTaskCount > 0);
                TaskTest.WaitFor(() => routerProxy.BrokerConn0.FetchRequestCallCount > 0);

                Assert.That(consumer.ConsumerTaskCount, Is.EqualTo(1), "Consumer should only create one consuming thread for partition 0.");
                Assert.That(routerProxy.BrokerConn0.FetchRequestCallCount, Is.GreaterThanOrEqualTo(1));
                Assert.That(routerProxy.BrokerConn1.FetchRequestCallCount, Is.EqualTo(0));
            }
        }
開發者ID:jsifantu,項目名稱:kafka-net,代碼行數:19,代碼來源:ConsumerTests.cs

示例15: ConnectionExceptionOnOneShouldCommunicateBackWhichMessagesFailed

        public void ConnectionExceptionOnOneShouldCommunicateBackWhichMessagesFailed()
        {
            //TODO is there a way to communicate back which client failed and which succeeded.
            var routerProxy = new BrokerRouterProxy(_kernel);
            routerProxy.BrokerConn1.ProduceResponseFunction = () => { throw new ApplicationException("some exception"); };

            var router = routerProxy.Create();
            var producer = new Producer(router);

            var messages = new List<Message>
                {
                    new Message{Value = "1"}, new Message{Value = "2"}
                };

            //this will produce an exception, but message 1 succeeded and message 2 did not.
            //should we return a ProduceResponse with an error and no error for the other messages?
            //at this point though the client does not know which message is routed to which server.
            //the whole batch of messages would need to be returned.
            var test = producer.SendMessageAsync("UnitTest", messages).Result;
        }
開發者ID:ntent-ad,項目名稱:kafka-net,代碼行數:20,代碼來源:ProducerTests.cs


注:本文中的BrokerRouterProxy.Create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。