How do I test the API gateway of a project in microservices

Asked

Viewed 42 times

0

How do I test the Api gateway of a project in microservices?

I configured Ocelot.json as below, and when I call in the browser /Billing get the bug:

Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HM69A8QLUIA0:00000005, previousRequestId: no previous request id, message: Error Code: ConnectionToDownstreamServiceError Message: Error connecting to downstream service, exception: System.Net.Http.HttpRequestException: Este host não é conhecido. (billingapi:8002)
       ---> System.Net.Sockets.SocketException (11001): Este host não é conhecido.
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
         at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
         at Ocelot.Requester.HttpClientHttpRequester.GetResponse(HttpContext httpContext) errors found in ResponderMiddleware. Setting error response for request path:/billingapi/GetFeeApp, request method: GET

Ocelot.json:

{
  "Routes": [
    // Billing.API
    {
      "DownstreamPathTemplate": "/api/v1/Billing",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "billingapi",
          "Port": "80"
        }
      ],
      "UpstreamPathTemplate": "/Billing",
      "UpstreamHttpMethod": [ "GET" ]
    }
  ]
}

Someone can help me what’s wrong ?

1 answer

0

If the data is exactly what you posted, what’s wrong is the host, which has to be the domain address. Instead of billingapi, must be some kind of address amazon.com.br, finally, the endpoint of this API.

P.S.: I don’t know if I’m using the right terms.

  • I’m testing via Docker, the host on Docker is billingapi

  • Yeah, except it has to be a DNS address or a public IP. It can be an internal IP as well, if it’s an internal test. HTTP connection over TCP/IP only talks to these things. Your application on Docker has to be accessible via one of these.

  • I may be talking some nonsense about the setup, which I don’t know how you do on Docker. But the idea of the error is that it tried to access the host via HTTP and did not locate. I imagine that he exposed an address mapping to internal address of the Docker instance, see that the error was on port 8002 and the configuration is 80. Some mapping has to be set up.

  • So if I’m going to test location if I pass the host as localhost it has to work right?

  • Maybe so, I believe so, I don’t know.

  • To work with localhost you will need to map the port to the host and put this port in the settings

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.