Invoking microservices through Zuul

Let's invoke random service through the service proxy now. The direct URL to a random microservice is http://localhost:8080/random. This is exposed by Microservice A, whose application name is microservice-a.

The URL structure to call a service through Zuul API Gateway is http://localhost:{port}/{microservice-application-name}/{service-uri}. So, the Zuul API Gateway URL for random service is http://localhost:8765/microservice-a/random. When you invoke random service through API Gateway, you get a response shown here. The response is similar to what you would typically get when directly calling the random service:

    [73,671,339,354,211]

The following is an extract from the Zuul Api Gateway log. You can see that the SimpleLoggingFilter that we created in Zuul API Gateway is executed for the request:

    c.m.s.z.filters.pre.SimpleLoggingFilter : Request Method : GET
URL: http://localhost:8765/microservice-a/random

The add service is exposed by service consumer, whose application name is service-consumer and the service URI is /add. So, the URL to execute the add service through the API Gateway is http://localhost:8765/service-consumer/add. The response from the service is shown here. The response is similar to what you would typically get when directly calling the add service:

    2488

The following is an extract from the Zuul API Gateway log. You can see that the initial add service call is going through the API Gateway:

    2017-03-28 14:05:17.514 INFO 83147 --- [nio-8765-exec-1] 
c.m.s.z.filters.pre.SimpleLoggingFilter : Request Method : GET
URL: http://localhost:8765/service-consumer/add

The add service calls random service on Microservice A. While the initial call to add service goes through the API Gateway, the call from add service (service consumer microservice) to random service (Microservice A) is not routed through API Gateway. In an ideal world, we would want all the communication to take place through API Gateway.

In the next step, let's make the requests from the service consumer microservice go through the API Gateway as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset