keijack / python-eureka-client

A eureka client written in python. Support registering your python component to Eureka Server, as well as calling remote services by pulling the the Eureka registry.
MIT License
189 stars 44 forks source link

Cannot call service from api-gateway #82

Closed PFernandezTorres closed 6 months ago

PFernandezTorres commented 6 months ago

I have configured a spring cloud api gateway to use for my other java microservices and when I set up the python microservice to the api gateway it does not seem to find it. All microservices use the same IP as stated on instance_ip field. This is my code for the eureka client:

import socket

from py_eureka_client import eureka_client

class EurekaConfig:

def __init__(self):
    pass

async def start_eureka(self):
    await eureka_client.init_async(eureka_server="http://localhost:8761/eureka/",
                                   app_name="analysis-service",
                                   instance_ip="192.168.1.41",
                                   instance_port=8000,
                                   instance_host="127.0.0.1",
                                   renewal_interval_in_secs=5)

The error displayed:

{ "timestamp": "2024-05-06T16:35:35.988+00:00", "path": "/analysis/hello", "status": 500, "error": "Internal Server Error", "message": "Failed to resolve 'analysis-service' [A(1)] after 2 queries ", "requestId": "62b3f170-2", "trace": "java.net.UnknownHostException: Failed to resolve 'analysis-service' [A(1)] after 2 queries \n\tat io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1125)\n\tSuppressed: The stacktrace has been enhanced by Reactor, refer to additional information below: \nError has been observed at the following site(s):\n\t__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]\n\tcheckpoint ⇢ AuthorizationWebFilter [DefaultWebFilterChain]\n\t*checkpoint ⇢ ExceptionTranslationWebFilter [DefaultWebFilterChain]\n\t__checkpoint ⇢ LogoutWebFilter [DefaultWebFilterChain]\n\tcheckpoint ⇢ ServerRequestCacheWebFilter [DefaultWebFilterChain]\n\t*checkpoint ⇢ SecurityContextServerWebExchangeWebFilter [DefaultWebFilterChain]\n\t__checkpoint ⇢ ReactorContextWebFilter [DefaultWebFilterChain]\n\tcheckpoint ⇢ CorsWebFilter [DefaultWebFilterChain]\n\t*checkpoint ⇢ HttpHeaderWriterWebFilter [DefaultWebFilterChain]\n\t__checkpoint ⇢ ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]\n\tcheckpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]\n\t*checkpoint ⇢ HTTP GET \"/analysis/hello\" [ExceptionHandlingWebHandler]\nOriginal Stack Trace:\n\t\tat io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1125)\n\t\tat io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:1072)\n\t\tat io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:444)\n\t\tat io.netty.resolver.dns.DnsResolveContext.onResponse(DnsResolveContext.java:675)\n\t\tat io.netty.resolver.dns.DnsResolveContext.access$500(DnsResolveContext.java:68)\n\t\tat io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:502)\n\t\tat io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)\n\t\tat io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)\n\t\tat io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)\n\t\tat io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)\n\t\tat io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)\n\t\tat io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)\n\t\tat io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)\n\t\tat io.netty.resolver.dns.DnsQueryContext.trySuccess(DnsQueryContext.java:345)\n\t\tat io.netty.resolver.dns.DnsQueryContext.finishSuccess(DnsQueryContext.java:336)\n\t\tat io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler.channelRead(DnsNameResolver.java:1382)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)\n\t\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)\n\t\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)\n\t\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)\n\t\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)\n\t\tat io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:97)\n\t\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)\n\t\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)\n\t\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)\n\t\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)\n\t\tat io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)\n\t\tat io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)\n\t\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\n\t\tat java.base/java.lang.Thread.run(Thread.java:840)\n" }

keijack commented 6 months ago

Please open the link http://localhost:8761/eureka/ in your browser, find out whether analysis-service is in the list.

PFernandezTorres commented 6 months ago

Sorry for not answering. Already solved. I deleted the instance_host and instance_ip field