How do I configure Vert.x event bus to work across cluster of Docker containers?

后端 未结 3 1569
执念已碎
执念已碎 2020-12-30 14:03

In my current setup, I\'m using the default multicast option of the Hazelcast cluster manager. When I link the instances of my containerized Vertx modules (via Docker networ

3条回答
  •  太阳男子
    2020-12-30 14:46

    found this solution that worked perfectly for me, below is my code snippet (important part is the options.setClusterHost()

    public class Runner {
    
        public static void run(Class clazz) {
            VertxOptions options = new VertxOptions();
            try {
                // for docker binding
                String local = InetAddress.getLocalHost().getHostAddress();
                options.setClusterHost(local);
            } catch (UnknownHostException e) { }
    
            options.setClustered(true);
    
            Vertx.clusteredVertx(options, res -> {
                if (res.succeeded()) {
                    res.result().deployVerticle(clazz.getName());
                } else {
                    res.cause().printStackTrace();
                }
            });
        }
    }
    
    public class Publisher extends AbstractVerticle {
    
        public static void main(String[] args) {
            Runner.run(Publisher.class);
        }
    
        ...
    }
    

    no need to define anything else...

提交回复
热议问题