Closed sid8491 closed 3 years ago
In the component, the IP was find by the try to connecting the component to one of the eureka server and try to get the IP address. So if your python component register to the eureka server in the same machine, the IP may be 127.0.0.1
.
s = socket.socket(socket_family, socket.SOCK_DGRAM)
s.connect((target_ip, target_port))
ip = s.getsockname()[0]
ok, so it does all that automatically. but how can we force it to show the ip-address like all other springboot applications are doing using preferIpAddress field?
instance_ip
could be set when initializing the client. And do you use the private ip or public ip in EC2?
private ip.
it could be set when initializing the client, but that would be hard-coding the IP. whereas, the application which is registering itself on eureka won't be knowing the private IP of EC2.
all the other applications (all of which are spring-boot applications) are not sending instance_ip, all of them are just setting preferIpAddress=true
.
Is there any similar parameter in py_eureka_client?
OK, I get it. In Amazon Data centre, all IPs and hostnames should also send to the Eureka, this is not quite well supported here, I'll figure it out.
oh thanks, that's great.
The component now will use the first none-loopback ip as the default instance ip, please check it in version 0.8.8. @sid8491
@keijack is there any property added to change the default behavior as well?
@keijack is there any property added to change the default behavior as well?
If you want to change the behavior, you can get your own ip/host via code, and set it to instance_ip
and instance_host
parameter.
@keijack thanks a ton. my issue is resolved.
it doesn't work,and my version is 0.9.3, eureka_client_init( instance_ip=)
@artpoplsh Could you please give more detail?
@artpoplsh Could you please give more detail?
I have solved this problem by call eureka_client_init(* instance_ip=ip,instance_host**=ip), could there be some sample paramter like preferIpAddress=true in springcloud
@artpoplsh you can find all arguments from code. they are
def __init__(self,
eureka_server: str = _DEFAULT_EUREKA_SERVER_URL,
eureka_domain: str = "",
region: str = "",
zone: str = "",
eureka_availability_zones: Dict[str, str] = {},
eureka_protocol: str = "http",
eureka_basic_auth_user: str = "",
eureka_basic_auth_password: str = "",
eureka_context: str = "/eureka",
prefer_same_zone: bool = True,
should_register: bool = True,
should_discover: bool = True,
app_name: str = "",
instance_id: str = "",
instance_host: str = "",
instance_ip: str = "",
instance_port: int = _DEFAULT_INSTNACE_PORT,
instance_unsecure_port_enabled: bool = True,
instance_secure_port: int = _DEFAULT_INSTNACE_SECURE_PORT,
instance_secure_port_enabled: bool = False,
data_center_name: str = _DEFAULT_DATA_CENTER_INFO, # Netflix, Amazon, MyOwn
renewal_interval_in_secs: int = _RENEWAL_INTERVAL_IN_SECS,
duration_in_secs: int = _DURATION_IN_SECS,
home_page_url: str = "",
status_page_url: str = "",
health_check_url: str = "",
secure_health_check_url: str = "",
vip_adr: str = "",
secure_vip_addr: str = "",
is_coordinating_discovery_server: bool = False,
metadata: Dict = {},
remote_regions: List[str] = [],
ha_strategy: int = HA_STRATEGY_RANDOM):
...
HA_STRATEGY_RANDOM
I see,but there is no argument like preferIpAddress
We need to register a service developed in python. When I am registering, it is showing
127.0.0.1:app-name:90
in the eureka dashboard. Other applications which were registered by spring-boot application are showing their ec2 instance ip instead of 127.0.0.1. Upon enquiring for the same, teams told me they setpreferIpAddress=true
field in their config.What would be the way to set this in python client? Is there any alternative parameter for this?
There is
instance_ip
parameter but we won't be knowing the ip address.Eureka config:
Versions: Python 3.6.9 py-eureka-client==0.8.6