我想爲兩個tomcat實例之間的pub/sub設置一個hazelcast主題。首先,我只有一個servlet,它在Tomcat啓動時初始化Hazelcast並創建主題。當通過HTTP GET調用時,這個servlet還會將消息發佈到主題。這裏是我的init()方法在servlet:couldnt connect to discovered master - hazelcast
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);
你指出的正是這個原因。我的網絡不允許多播。感謝讓我走了。 – rkrishnan
沒問題。不用謝。 – pveentjer