简体   繁体   English

Wildfly-Swarm Consul服务发现 - 无效的服务地址

[英]Wildfly-Swarm Consul service discovery - Invalid service address

I'm developing Wildfly-Swarm app and I want to use Consul as my service discovery. 我正在开发Wildfly-Swarm应用程序,我想使用Consul作为我的服务发现。 So I added topology-consul fraction, set my Consul path in project-defaults.yml and added @Advertise("service-name") to my Endpoint. 所以我添加了topology-consul分数,在project-defaults.yml中设置了Consul路径,并将@Advertise("service-name")到了我的Endpoint。

And if I start my application using 如果我开始使用我的应用程序

java –jar my-swarm-app.jar

everything works just fine. 一切正常。

My project-defaults.yml: 我的project-defaults.yml:

service:
  catalog:
    service-name: "service-name"
swarm:
  port:
    offset: 501
  consul:
    url: "http://172.30.3.80:8500"

But when I pack my fat jar inside Docker image with this Dockerfile: 但是当我使用这个Dockerfile将我的胖罐包装在Docker镜像中时:

FROM openjdk:8-jre-alpine
ADD my-swarm-app.jar /opt/my-swarm-app.jar
EXPOSE 8581
ENTRYPOINT ["java", "-jar", "-Djava.net.preferIPv4Stack=true", "/opt/my-swarm-app.jar"]

Build it: 建立它:

docker build -f Dockerfile -t my-swarm-app .

And run it like so: 并运行它:

docker run -p 8581:8581 my-swarm-app

I get following exception: 我得到以下异常:

2017-09-26 15:17:54,240 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service swarm.topology.register.consent-service.http: org.jboss.msc.service.StartException in service swarm.topology.register.consent-service.http: com.orbitz.consul.ConsulException: Invalid service address
        at org.wildfly.swarm.topology.deployment.RegistrationAdvertiser.start(RegistrationAdvertiser.java:79)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.orbitz.consul.ConsulException: Invalid service address
        at com.orbitz.consul.AgentClient.register(AgentClient.java:180)
        at com.orbitz.consul.AgentClient.register(AgentClient.java:184)
        at org.wildfly.swarm.topology.consul.runtime.Advertiser.advertise(Advertiser.java:65)
        at org.wildfly.swarm.topology.consul.runtime.ConsulTopologyConnector.advertise(ConsulTopologyConnector.java:60)
        at org.wildfly.swarm.topology.deployment.RegistrationAdvertiser.start(RegistrationAdvertiser.java:77)
        ... 5 more

Am I doing something wrong? 难道我做错了什么?

EDIT: I have tryed self implementing service discovery using consul-api. 编辑:我尝试使用consul-api自我实现服务发现。

        <dependency>
            <groupId>com.ecwid.consul</groupId>
            <artifactId>consul-api</artifactId>
            <version>1.2.4</version>
        </dependency>

Like so: 像这样:

@ApplicationScoped
public class Config {

    private ConsulClient client;

    @Inject
    @ConfigurationValue("swarm.http.port")
    private Integer port;

    public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext context) {
        client = new ConsulClient("http://172.30.3.80:8500");

        // register new service with associated health check
        NewService newService = new NewService();
        newService.setId("myapp_02");
        newService.setTags(Collections.singletonList("EU-East"));
        newService.setName("myapp_aaa");
        newService.setPort(port);

        client.agentServiceRegister(newService);
    }
}

And its working inside docker image. 它在docker图像中工作。 Is this maybe a bug in Wildfly-Swarm topology fraction or am I missing some configuration? 这可能是Wildfly-Swarm拓扑分数中的一个错误,还是我错过了一些配置?

EDIT 2: I found that the issue is with wildfly-swarm paramater -Djava.net.preferIPv4Stack=true . 编辑2:我发现问题出在wildfly-swarm -Djava.net.preferIPv4Stack=true When I run jar file with this parameter I get same exception but if I remove it Dockerfile for creating docker image and run it i get this exception: 当我使用此参数运行jar文件时,我得到相同的异常,但如果我删除Dockerfile以创建docker镜像并运行它,我会得到以下异常:

2017-09-27 20:34:46,460 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.undertow.listener.default: org.jboss.msc.service.StartException in service jboss.undertow.listener.default: WFLYUT0082: Could not start 'default' listener.
        at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:153)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Protocol family unavailable
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:171)
        at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:245)
        at org.wildfly.extension.undertow.HttpListenerService.startListening(HttpListenerService.java:126)
        at org.wildfly.extension.undertow.ListenerService.start(ListenerService.java:142)
        ... 5 more

Here is the link to github project where you can reproduce the error: https://github.com/pkristja/wildfly-swarm-consul-demo 这是github项目的链接,您可以在其中重现错误: https//github.com/pkristja/wildfly-swarm-consul-demo

It looks similar to this problem. 它看起来类似于这个问题。

Can you try to add the swarm.bind.address: 127.0.0.1 to yml configuration. 您可以尝试将swarm.bind.address: 127.0.0.1添加到yml配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM