thangchung / magazine-website

:mouse: A magazine website (using .NET Core, ASP.NET Core, EF Core) with DDD, CQRS, microservices, asynchronous programming applied...
https://github.com/thangchung/magazine-website
178 stars 51 forks source link

Create a Proxy for the API gateway #6

Closed thangchung closed 8 years ago

thangchung commented 8 years ago

Problem: All requests have to hit into the API gateway, then it will dispatch them into the correct one service, based on the url, e.g. https://localhost:8080/magazine/api/categories then it should forward to http://localhost:5000/api/categories Solution: Have a look at http://josephwoodward.co.uk/2016/07/proxying-http-requests-asp-net-core-using-kestrel

thangchung commented 8 years ago

It should be coordinate with the service discovery to get the registered services, then forward it to a correct one. And the Reactive should apply in this layer, and also need a circuit breaker in this layer as well.

thangchung commented 8 years ago

Should not use current approach, we need to refactor. Ideas:

  1. Write a middleware for processing the URL with a list of pattern like [sample_service, magazine_service...]
  2. Process by call to service discovery to resolve the real URL to the service, then the remain parts of the URL after the service, e.g. http://api_gateway:8080/sample_service/api/values
  3. submit the request using Reactive approach to avoid blocking on the server side

Reference link at https://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client

thangchung commented 8 years ago

We need the protocol translation for calling to underneath service as well. We will support 2 protocols: REST and AMQP.