Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] I want the host registered with the gateway to be the hostname that I specify. How can I achieve this? #5601

Open
topcatv opened this issue Aug 1, 2024 · 4 comments
Labels
type: question Further information is requested

Comments

@topcatv
Copy link

topcatv commented Aug 1, 2024

Question

When using shenyu-spring-boot-starter-client-springmvc, I want the host registered with the gateway to be the hostname that I specify. How can I achieve this?
Because I used the service in k8s to provide services, therefore I used the following configuration in the configuration file.

shenyu:
  register:
    registerType: http
    serverLists: http://shenyu-admin-svc:9095
    props:
      username: admin
      password: xxxxx
  client:
    http:
      props:
        host: biz-service
        contextPath: /biz
        appName: biz

However, after registering to the gateway, it was found that the upstream of the divide was still the IP address of this service instead of the service name. Through source code analysis, it was found in the org.apache.shenyu.client.springmvc.init.SpringMvcClientEventListener#buildURIRegisterDTO method

try {
    return URIRegisterDTO.builder()
            .contextPath(getContextPath())
            .appName(getAppName())
            .protocol(protocol)
            .host(super.getHost())
            .port(Integer.valueOf(getPort()))
            .rpcType(RpcTypeEnum.HTTP.getName())
            .eventType(EventType.REGISTER)
            .build();
} catch (ShenyuException e) {
    throw new ShenyuException(e.getMessage() + "please config ${shenyu.client.http.props.port} in xml/yml !");
}
public String getHost() {
    return IpUtils.isCompleteHost(this.host) ? this.host
            : IpUtils.getHost(this.host);
}

IpUtils.isCompleteHost(this.host) returns false, so the host IP will be fetched. Can this be changed here to support configuring the host name or svc in k8s?

@topcatv topcatv added the type: question Further information is requested label Aug 1, 2024
@Aias00
Copy link
Contributor

Aias00 commented Aug 1, 2024

hi, the IpUtils.isCompleteHost method is for checking whether the host is complete, and it actually just support ip now

@topcatv
Copy link
Author

topcatv commented Aug 2, 2024

Whether to consider supporting hostname or service name of k8s service

@x519286925
Copy link

Whether to consider supporting hostname or service name of k8s service

我也发现了这个问题,然后我用多语言的http客户端用调接口的方式倒可以用hostname,不知道是设计问题还是什么,也能实现正常转发
https://shenyu.apache.org/zh/docs/developer/developer-shenyu-client

I also discovered this issue, and then I used a multilingual HTTP client to call the interface using hostname. I don't know if it's a design problem or something, but I can still achieve normal forwarding

😄

@Aias00
Copy link
Contributor

Aias00 commented Aug 5, 2024

hi, we will discuss thia problem later, and may solve this problem in next version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants