代码之家  ›  专栏  ›  技术社区  ›  ZAID SAHIL

由两台不同的机器组成的群集具有高可用性?

  •  0
  • ZAID SAHIL  · 技术社区  · 6 年前

    我有两台不同的机器。一个配置IP 192.168.2.100,另一个配置IP 192.168.2.101。 这是第一条竖线的代码:

     public class Sender extends AbstractVerticle {
    
    public static void main(String... args) {
    
            // Configuration du cluster manager
            Config config = new Config();
            config.getNetworkConfig().getJoin().getTcpIpConfig().addMember("192.168.2.101");
    
            VertxOptions options = new VertxOptions();
            options.setClusterManager(new HazelcastClusterManager());
            options.setClusterHost("192.168.2.100");
            options.setClustered(true);
            options.setHAEnabled(true);
    
    
            Vertx.clusteredVertx(options, vertx ->
                    vertx.result().deployVerticle(Sender.class.getName(), new DeploymentOptions().setHa(true))
            );
        }
    
    
        @Override
        public void start() throws Exception {
    
            vertx.setPeriodic(5000, id -> {
                vertx.eventBus().send("Address", "message",rep->{
                System.out.println("response : "+rep.result().body());
                });
            });
        }
    }
    

    这是第二个垂直的代码:

     package com.vetx.Consumer;
    import com.hazelcast.config.Config;
    
    
    
    public class Consumer extends AbstractVerticle {
    
        private String name = null;
    
        public Consumer(String name) {
            this.name = name;
        }
        public Consumer(){
    
        }
    
        public static void main(String... args) {
    
            // Configuration du cluster manager
            Config config = new Config();
            config.getNetworkConfig().getJoin().getTcpIpConfig().addMember("192.168.2.100");
    
            VertxOptions options = new VertxOptions();
            options.setClusterManager(new HazelcastClusterManager());
            options.setClusterHost("192.168.2.101");
            options.setClustered(true);
            options.setHAEnabled(true);
    
    
    
            Vertx.clusteredVertx(options, vertx ->
                    vertx.result().deployVerticle(Consumer.class.getName(), new DeploymentOptions().setHa(true))
            );
        }
    
    
        @Override
        public void start() throws Exception {
    
            vertx.eventBus().consumer("Address", message -> {
                System.out.println(" received message: " +message.body());
               message.reply("Success");
            });
        }
    }
    

    我尝试使用集群的高可用性来实现消费者消费消息和发送者发送消息。当尝试在故障转移后杀死发送方以重新部署verticle时,我遇到以下异常:

        SEVERE: Failed to redeploy verticle after failover
    java.lang.ClassNotFoundException: com.vetx.Sender.Sender
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at io.vertx.core.impl.JavaVerticleFactory.createVerticle(JavaVerticleFactory.java:37)
        at io.vertx.core.impl.DeploymentManager.createVerticles(DeploymentManager.java:229)
        at io.vertx.core.impl.DeploymentManager.lambda$doDeployVerticle$2(DeploymentManager.java:202)
        at io.vertx.core.impl.FutureImpl.setHandler(FutureImpl.java:76)
        at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:171)
        at io.vertx.core.impl.DeploymentManager.doDeployVerticle(DeploymentManager.java:143)
        at io.vertx.core.impl.DeploymentManager.deployVerticle(DeploymentManager.java:131)
        at io.vertx.core.impl.HAManager.doDeployVerticle(HAManager.java:281)
        at io.vertx.core.impl.HAManager.processFailover(HAManager.java:553)
        at io.vertx.core.impl.HAManager.checkFailover(HAManager.java:489)
        at io.vertx.core.impl.HAManager.nodeLeft(HAManager.java:309)
        at io.vertx.core.impl.HAManager.access$100(HAManager.java:102)
        at io.vertx.core.impl.HAManager$1.nodeLeft(HAManager.java:152)
        at io.vertx.spi.cluster.hazelcast.HazelcastClusterManager.memberRemoved(HazelcastClusterManager.java:325)
        at com.hazelcast.internal.cluster.impl.ClusterServiceImpl.dispatchEvent(ClusterServiceImpl.java:916)
        at com.hazelcast.internal.cluster.impl.ClusterServiceImpl.dispatchEvent(ClusterServiceImpl.java:88)
        at com.hazelcast.spi.impl.eventservice.impl.LocalEventDispatcher.run(LocalEventDispatcher.java:56)
        at com.hazelcast.util.executor.StripedExecutor$Worker.process(StripedExecutor.java:217)
        at com.hazelcast.util.executor.StripedExecutor$Worker.run(StripedExecutor.java:200)
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   sertug    6 年前

    两个集群成员都应该具有类 com.vetx.Sender.Sender 因为它将在两侧被序列化/反序列化。似乎其中一个成员没有。 此外,您是否确保成员可以组成2个集群?我看到您的网络配置在每个主机上都有一个ip getTcpIpConfig().addMember("192.168.2.101") ,最佳做法是在所有主机上添加所有ip,即在所有主机上具有相同的网络配置,以避免混淆。