无法连接到已发现的主人 - 淡褐色

时间:2014-01-23 05:19:27

标签: java tomcat hazelcast

我正在尝试在两个tomcat实例之间为pub / sub设置hazelcast主题。首先,我只有一个初始化Hazelcast的servlet,并在tomcat启动时创建主题。当通过HTTP GET调用时,此servlet还将向主题发布消息。这是我在servlet中的init()方法:

Config cfg = new Config();

System.out.println("hzapp: Creating hazelcast instance...");
hzInstance = Hazelcast.newHazelcastInstance(cfg);
System.out.println("hzapp: Created hazelcast instance.");

topic = hzInstance.getTopic("my-topic");

System.out.println("hzapp: Adding listener to the topic...");
topic.addMessageListener(new HzMessageListener());
System.out.println("hzapp: listener added to the topic.");

servlet的doGet(req,res)方法只是向主题发布消息,如下所示:

String message = request.getParameter("message");
System.out.println("hzapp: publishing message: " + message);
topic.publish(message);
System.out.println("hzapp: published message: " + message);

HzMessageListener不执行任何操作,只打印收到的消息:

public void onMessage(Message<String> message) {
    System.out.println("hzapp: Message Received: " + message.getMessageObject());
}

现在,我面临的问题是,当我启动tomcat时,它会给我以下错误:

INFO: Starting Servlet Engine: Apache Tomcat/6.0.36
hzapp: Creating hazelcast instance...
Jan 23, 2014 10:43:26 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Jan 23, 2014 10:43:26 AM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[192.168.1.10]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0%0,localport=5702], bind any local is true
Jan 23, 2014 10:43:26 AM com.hazelcast.system
INFO: [192.168.1.10]:5702 [dev] Hazelcast Community Edition 3.1.4 (20140111) starting at Address[192.168.1.10]:5702
Jan 23, 2014 10:43:26 AM com.hazelcast.system
INFO: [192.168.1.10]:5702 [dev] Copyright (C) 2008-2013 Hazelcast.com
Jan 23, 2014 10:43:26 AM com.hazelcast.instance.Node
INFO: [192.168.1.10]:5702 [dev] Creating MulticastJoiner
Jan 23, 2014 10:43:26 AM com.hazelcast.core.LifecycleService
INFO: [192.168.1.10]:5702 [dev] Address[192.168.1.10]:5702 is STARTING
Jan 23, 2014 10:43:26 AM com.hazelcast.nio.SocketConnector
INFO: [192.168.1.10]:5702 [dev] Connecting to /192.168.1.10:5701, timeout: 0, bind-any: true
Jan 23, 2014 10:43:26 AM com.hazelcast.nio.TcpIpConnectionManager
INFO: [192.168.1.10]:5702 [dev] 55635 accepted socket connection from /192.168.1.10:5701
Jan 23, 2014 10:43:50 AM com.hazelcast.instance.Node
WARNING: [192.168.1.10]:5702 [dev] Trying to rejoin: 
======================================================
Couldn't connect to discovered master! tryCount: 50
address: Address[192.168.1.10]:5702
masterAddress: Address[192.168.1.10]:5701
multicast: true
connection: null
======================================================

知道这里出了什么问题吗?我正在使用Hazelcast 3.1.4版,我在WEB-INF / lib中使用了hazelcast-all-3.1.4.jar。

无论我尝试过什么,它都不会超越Hazelcast.newHazelcastInstance(cfg);

1 个答案:

答案 0 :(得分:4)

你能尝试使用tcp ip discovery而不是多播来确保除了多播之外别无其他问题:

Config config = new Config();
JoinConfig join = config.getNetworkConfig().getJoin();
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().setEnabled(true);

然后我们缩小了问题的范围。可能是你的网络不支持多播btw ..这可能是原因。