

The latest version of the package targets. Ocelot is designed to work with ASP.NET Core only. Ocelot is basically a set of middleware that you can apply in a specific order. Implementing your API Gateways with Ocelot That way, the client app won't directly access the microservice. And you can avoid that by setting the additional level of indirection of the API Gateway (Ocelot, in this case). However, direct-access communication to the microservice, in this case through the external port 5101, is precisely what you want to avoid in your application.
#EWALLET API CODE#
Testing the Catalog microservice with its Swagger UIĪt this point, you could set a breakpoint in C# code in Visual Studio, test the microservice with the methods exposed in Swagger UI, and finally clean-up everything with the docker-compose down command. Then, you can directly access the Catalog microservice and see its methods through the Swagger UI accessing directly through that "external" port, in this case :įigure 6-31. In this case, the SQL Server container and RabbitMQ container.


#EWALLET API PLUS#
This command only runs the catalog-api service container plus dependencies that are specified in the docker-compose.yml. docker-compose run -service-ports catalog-api
#EWALLET API FULL#
Either run the full eShopOnContainers solution from Visual Studio (it runs all the services in the docker-compose files), or start the Catalog microservice with the following docker-compose command in CMD or PowerShell positioned at the folder where the docker-compose.yml and are placed. Run the catalog microservice in your local Docker host.

When deploying to those environments you use different configuration files where you won't publish directly any external port for the microservices but, you'll always use the reverse proxy from the API Gateway. Normally, you won't be deploying with docker-compose into a production environment because the right production deployment environment for microservices is an orchestrator like Kubernetes or Service Fabric. But this port shouldn't be used by the application when using an API Gateway, only to debug, run, and test just the Catalog microservice. You can see how in the configuration the internal port for the Catalog container is port 80, but the port for external access is 5101. # The API Gateway redirects and access through the internal port (80). "5101:80" # Important: In a production environment you should remove the external port (5101) kept here for microservice debugging purposes. Here's an example of the file for the Catalog microservice: catalog-api: That's why in eShopOnContainers, the external ports are still specified even when they won't be used by the API Gateway or the client apps. However, when developing, you want to access the microservice/container directly and run it through Swagger. For this specific reason, why you want to use the API Gateway, to avoid the direct communication between the client apps and the microservices. Those external ports shouldn't be published when deploying to a production environment. The port 80 shown in the code is internal within the Docker host, so it can't be reached by client apps.Ĭlient apps can access only the external ports (if any) published when deploying with docker-compose.
#EWALLET API PC#
Regarding the microservice URL, when the containers are deployed in your local development PC (local Docker host), each microservice's container always has an internal port (usually port 80) specified in its dockerfile, as in the following dockerfile: FROM /dotnet/aspnet:3.1 AS base The HTTP request will end up running that kind of C# code accessing the microservice database and any additional required action. Consider using Ocelot GetItemById(int id) However, we've retained this section in the guide so you can consider Ocelot as a simple, capable, and lightweight API Gateway suitable for production-grade scenarios.Īlso, latest Ocelot version contains a breaking change on its json schema. We made this design choice because of Envoy's built-in support for the WebSocket protocol, required by the new gRPC inter-service communications implemented in eShopOnContainers. The reference microservice application eShopOnContainers is currently using features provided by Envoy to implement the API Gateway instead of the earlier referenced Ocelot.
