private async Task <HttpResponseMessage> failedCircuit(BrokenCircuitException exception, ReceiverModel surveyValues) { var client = _createClient("22"); HttpResponseMessage response = await client.PostAsJsonAsync("api/handler", surveyValues); return(response); }
private async Task<HttpResponseMessage> HandleBrokenCircuit(BrokenCircuitException ex) { _logger.LogError(" Backup Infrastructure Accepted Paymentmethods" + ex.Message); var client = _httpClientFactory.CreateClient(ALTERNATIVECLIENT); HttpResponseMessage response = await client.GetAsync( SUBURI); return response; }
public void SetUp() { var fakeResponseDelegatingHandler = new FakeResponseDelegatingHandler(); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.InternalServerError)); fakeResponseDelegatingHandler.AddFakeResponse(new Uri(TEST_URI), () => new HttpResponseMessage(HttpStatusCode.OK)); httpClient = new HttpClient(new CircuitBreakingDelegatingHandler(EXCEPTIONS_ALLOWED_BEFORE_BREAKING, circuitOpenDuration, fakeResponseDelegatingHandler)); // trigger circuit break response1 = httpClient.GetAsync(TEST_URI).Result; response2 = httpClient.GetAsync(TEST_URI).Result; // circuit should be open try { var response3 = httpClient.GetAsync(TEST_URI).Result; } catch (BrokenCircuitException brokenCircuitException) { httpClientException = brokenCircuitException; } WaitCircuitToBeClosed(); response4 = httpClient.GetAsync(TEST_URI).Result; }
private async Task <HttpResponseMessage> failedCircuit(BrokenCircuitException exception) { _logger.LogError(" Trying second Payment " + exception.Message); var client = _clientFactory.CreateClient("https://iegeasycreditcardservice-2.azurewebsites.net/"); HttpResponseMessage response = await client.GetAsync("api/AcceptedCreditCards"); return(response); }
public void When_An_Error_Should_Break_The_Circuit() { //break circuit with retries _failedException = Catch.Exception(() => _commandProcessor.Post(_myCommand)); //now respond with broken ciruit _circuitBrokenException = (BrokenCircuitException)Catch.Exception(() => _commandProcessor.Post(_myCommand)); _messagingProducer.SentCalledCount.Should().Be(4); _failedException.Should().BeOfType <Exception>(); _circuitBrokenException.Should().BeOfType <BrokenCircuitException>(); }
public void When_An_Error_Should_Break_The_Circuit() { //break circuit with retries _failedException = Catch.Exception(() => _commandProcessor.Post(_myCommand)); //now respond with broken ciruit _circuitBrokenException = (BrokenCircuitException)Catch.Exception(() => _commandProcessor.Post(_myCommand)); Assert.AreEqual(4, _messagingProducer.SentCalledCount); Assert.IsInstanceOf(typeof(Exception), _failedException); Assert.IsInstanceOf(typeof(BrokenCircuitException), _circuitBrokenException); }
public ErrorResult GetError(BrokenCircuitException <HttpResponseMessage> exception) { var detailsErrorMessage = HttpCallException.BuildMessage(exception.Result.RequestMessage.RequestUri, exception.Result.RequestMessage.Method, exception.Result.StatusCode, exception.Result.ReasonPhrase); dynamic details = new { RequestUrl = exception.Result.RequestMessage.RequestUri.ToString(), RequestMethod = exception.Result.RequestMessage.Method.Method, ErrorMessage = detailsErrorMessage, ResponseBody = GetResponseBody(exception.Result.Content.ReadAsStringAsync().Result), StackTrace = exception.StackTrace }; var error = new Error(DefaultInstance, ErrorCode.System.ToString(), exception.Message, details); return(new ErrorResult(error)); }
public static int StatusCode(this BrokenCircuitException exception) { return(StatusCode((HttpOperationException)exception.InnerException)); }