EasyKeys.com production ready shipment library for FedEx, Stamps and USPS shipping providers.
If you like or are using this project please give it a star. Thanks!
- EasyKeys.Shipping.FedEx.Abstractions
- EasyKeys.Shipping.FedEx.AddressValidation
- EasyKeys.Shipping.FedEx.Rates
- EasyKeys.Shipping.FedEx.Shipment
- EasyKeys.Shipping.FedEx.Tracking
- EasyKeys.Shipping.FedEx.Console - Sample Application
- EasyKeys.Shipping.Stamps.Abstractions
- EasyKeys.Shipping.Stamps.AddressValidation
- EasyKeys.Shipping.Stamps.Rates
- EasyKeys.Shipping.Stamps.Shipment
- EasyKeys.Shipping.Stamps.Tracking
- EasyKeys.Shipping.Stamps.Console - Sample application
var request = new ValidateAddress(model?.RequestId ?? Guid.NewGuid().ToString(), originalAddress, originalAddress);
var response = await _policy.ExecuteAsync(
async (ctx, ct) => await _validationProvider.ValidateAddressAsync(request, ct),
new Context
{
[_policyContextMethod] = "ValidateAsync"
},
cancellationToken);
private IAsyncPolicy GetRetryWithTimeOutPolicy()
{
// each call is limited to 30 seconds in case when fedex is non-reponsive and it is 1min timeout, it is way to long
// The request channel timed out attempting to send after 00:01:00.
// Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
var timeoutPolicy = Policy.TimeoutAsync(30, TimeoutStrategy.Pessimistic);
var jitterer = new Random();
return Policy
.Handle<TimeoutRejectedException>()
.WaitAndRetryAsync(
retryCount: 3, // exponential back-off plus some jitter
sleepDurationProvider: (retryAttempt, context) =>
{
return TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))
+ TimeSpan.FromMilliseconds(jitterer.Next(0, 200));
},
onRetry: (ex, span, context) =>
{
var methodName = context[_policyContextMethod] ?? "MethodNotSpecified";
_logger.LogWarning(
"{Method} wait {Seconds} to execute with exception: {Message} for named policy: {Policy}",
methodName,
span.TotalSeconds,
ex.Message,
context.PolicyKey);
})
.WithPolicyKey($"{nameof(FedExAddressValidationProvider)}WaitAndRetryAsync")
.WrapAsync(timeoutPolicy);
}