hazelcast客户端iTopic没有看到这个话题

时间:2015-08-28 09:06:37

标签: hazelcast

我在hazelcast实例上有以下代码:

ITopic<String> topic;
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
topic = hz.getTopic("data");

数据重复发布到主题

String event = "abc123"
topic.publish(event);

然后在局域网上的另一台机器上运行客户端,如下所示:

public class Listener implements MessageListener<String>
{
    ClientConfig clientConfig = new ClientConfig();     
    clientConfig.getNetworkConfig().addAddress("192.168.21.89:5701");
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

    ITopic<String> topic = client.getTopic("data");
    topic.addMessageListener(new Listener());  

    public void onMessage(Message<String> m) {
        System.out.println("onMessage");
    }
}

客户端找到hz节点并启动,但在iTopic上看不到任何数据消息。我认为hz实例和客户端默认会自动发现对方?我是否必须以某种方式为网络配置hz?

客户端日志显示:

2015-09-01 15:43:05,518 INFO Listener [main] In main()
In main()
Sep 01, 2015 3:43:05 PM com.hazelcast.core.LifecycleService
INFO: HazelcastClient[hz.client_0_dev][3.5] is STARTING
Sep 01, 2015 3:43:05 PM com.hazelcast.core.LifecycleService  
INFO: HazelcastClient[hz.client_0_dev][3.5] is STARTED  
Sep 01, 2015 3:43:06 PM com.hazelcast.core.LifecycleService  
INFO: HazelcastClient[hz.client_0_dev][3.5] is CLIENT_CONNECTED  
Sep 01, 2015 3:43:06 PM com.hazelcast.client.spi.impl.ClientMembershipListener  
INFO:  
Members [1] {  
    Member [192.168.21.89]:5701  
}

1 个答案:

答案 0 :(得分:0)

这是我自己的问题,因为我实际上并没有发布我想听的数据。 Aaargh!