Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildfly-Swarm Consul service discovery - Invalid service address

I’m developing Wildfly-Swarm app and I want to use Consul as my service discovery. So I added topology-consul fraction, set my Consul path in project-defaults.yml and added @Advertise("service-name") to my Endpoint.

And if I start my application using

java –jar my-swarm-app.jar

everything works just fine.

My 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:

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.

        <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. Is this maybe a bug in Wildfly-Swarm topology fraction or am I missing some configuration?

EDIT 2: I found that the issue is with wildfly-swarm paramater -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:

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

like image 792
Kiki Avatar asked Oct 17 '22 05:10

Kiki


1 Answers

It looks similar to this problem.

Can you try to add the swarm.bind.address: 127.0.0.1 to yml configuration.

like image 105
Anže Maleš Avatar answered Nov 15 '22 06:11

Anže Maleš