wcf - Type safety when using requestUri of HttpClient.GetAsync(String) in Micro Services -
in micro-service architecture in .net, there many webapi services. interact each other uri strings.
httpclient client = new httpclient() client.baseaddress = new uri("http://localhost:9000/"); httpresponsemessage response = await client.getasync("api/products/1"); httpresponsemessage response = await client.getasync("api/products");
the magic strings api/products/1 causes code maintainability problem - magic strings spread in code. consumer or client application can break if there service changes in apicontroller or action. there no proxy wcf provides client can use type safe service calls.
how can bring type safety webapi service calls?
these micro services should not coupled , communicating directly each other. 1 of key points of micro services decouple services not dependent on each other. way 1 micro service can taken down or updated , rest of micro services not affected. if use api gateway, gateway thing need change if services change. if direct service-to-service communication needed, use messaging or queue service facilitate this. each service subscribe needs other services without knowing it's endpoints (or interfaces are). gateway knows micro service's interfaces , can update if interfaces changed. api gateway interface external clients need know about. these interfaces can have versioning strategy , these interfaces ones "public". no micro service interfaces should public.
Comments
Post a Comment