ServiceFabric.AutoRest is a small client communication library, created to simplify using AutoRest generated client libraries in Azure Service Fabric reliable services. The primary use-case is service-to-service communication over HTTP leveraging the strongly typed client code generated by AutoRest.
Extends the capabilities found in the Microsoft.ServiceFabric.Services.Communication.Client
namespace, such as automatic service uri resolution, retry logic, endpoint caching and more.
-
Add a Stateless (or Statefull) Web API service to your Service Fabric application. The service will be called by other Service Fabric services.
-
Add Swagger to the Web API service.
-
Generate client code from the Swagger specification exposed by the Web API service.
-
Install ServiceFabric.AutoRest from nuget.org in another Service Fabric service that needs to communicate with the Web API service.
-
Create a shared instance of
RestCommunicationClientFactory
:static RestCommunicationClientFactory<StatelessClient> communicationClientFactory; static ClientService() { communicationClientFactory = new RestCommunicationClientFactory<StatelessClient>(); }
-
Create an instance of
RestServicePartitionClient<StatelessClient>
and use it to call the Web API Service:public async Task<IEnumerable<string>> GetValuesFromOtherService() { Uri serviceUri = new Uri("fabric:/ServiceFabric.AutoRest.Clients/WebApi"); IRestServicePartitionClient<StatelessClient> partitionClient = new RestServicePartitionClient<StatelessClient>( communicationClientFactory, serviceUri, ServicePartitionKey.Singleton); var result = await partitionClient.InvokeWithRetryAsync( async c => await c.RestApi.Values.GetAllAsync()); return result; }
- Dependency Injection support, through interfaces.
- Call multiple service partitions in Statefull services using the
RestServicePartitionClientFactory
class - Leverages Service Fabric retry strategy (IMPORTANT: AutoRest' default retry strategy is disabled as it interferes with SF build-in retry strategy)
- Extendable exception handling
- Extendable http delegating handler pipeline
- Support for client credentials
- New extension points through events to better control client creation and validation
[walk-through of sample to be added]