问题
I have 2 applications (A1 and A2) hosted in azure service fabric, each application with its own stateless reliable micro-service (S1 and S2). The app A1 depends on S1 and app A2 depends on S2. In addition, S2 service depends on S1. Both S2 and S1 are owin hosted REST api services. When the request for A2 ends up in S2, I need to make a call from S2 to S1. I am trying to figure out the optimized way of doing this.
1) Should I use HttpClient in S2 to call S1? How do I get the resolution for S1 in side of S2? Is it just published uri for S1 and fabric will know how to optimize those calls? 2) Should I implement 2 listeners in S1 (one http endpoint for A1 clients and one service remoting endpoint with an interface to call from S2)? Again how does address resolution work?
In either case, short code samples would be of immense help.
Thanks. Raghu/..
回答1:
Yes S2 can use HttpClient to call S1. First S2 needs to resolve an address for S1. Service Fabric has APIs for that. Here's some documentation that gives you an overview of how this works:
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-connect-and-communicate-with-services/
https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication/
And a simple sample application that has one service that resolves the address of a second service (it's resolving a stateful service but it works the same way for stateless)
https://github.com/Azure-Samples/service-fabric-dotnet-getting-started/tree/master/Services/WordCount/WordCount.WebService
来源:https://stackoverflow.com/questions/37617556/optimized-http-service-invocation-with-in-azure-service-fabric