private static void ProcessUserRegistration(string cmd) { var newUser = new LoyaltyProgramUser { Name = cmd.Substring(1).Trim() }; var response = client.RegisterUser(newUser).Result; PrettyPrintResponse(response); }
private async Task <HttpResponseMessage> DoUpdateUser(LoyaltyProgramUser user) { using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri($"http://{this.hostName}"); httpClient.DefaultRequestHeaders.Add("Accept", "*/*"); var response = await httpClient.PutAsync($"/users/{user.Id}", new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json")); ThrowOnTransientFailure(response); return(response); } }
private async Task<LoyaltyProgramUser> DoRegisterUser(LoyaltyProgramUser newUser) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(_loyaltyServiceHost); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var content = JsonConvert.SerializeObject(newUser); var response = await client.PostAsync("/users/", new StringContent(content, Encoding.UTF8, "application/json")); ThrowOnTransientFailure(response); return JsonConvert.DeserializeObject<LoyaltyProgramUser> (await response.Content.ReadAsStringAsync()); } }
public async Task <HttpResponseMessage> UpdateUser(LoyaltyProgramUser user) { return(await exponentialRetryPolicy.Execute(() => DoUpdateUser(user))); }
public async Task <HttpResponseMessage> RegisterUser(LoyaltyProgramUser newUser) { return(await exponentialRetryPolicy.Execute(() => DoRegisterUser(newUser))); }
public async Task<LoyaltyProgramUser> UpdateUser(LoyaltyProgramUser user) { return await _circuitBreakerPolicy.ExecuteAsync(() => DoUpdateUser(user)); }
//it's not working the way it was intended; check health should be done manually //private static readonly Policy _retryHeartBeatPolicy = Policy.Handle<Exception>() // .WaitAndRetryAsync(3, attempt => TimeSpan.FromMilliseconds(200 * Math.Pow(2, attempt)), // async (exc, ts) => await CheckHealth()); public async Task<LoyaltyProgramUser> RegisterUser(LoyaltyProgramUser newUser) { return await _retryExponentialPolicy.ExecuteAsync(() => DoRegisterUser(newUser)); }