我试图将HazelCast用作消息队列
我将hazelcast作为一个独立的服务器运行
我有两个hazelcast客户端:Server1和Server2
我想在Server1和Server2上发送消息。
在server1,我有:
public class ClusterManager implements MessageListener {
static ITopic topicServer1;
static ITopic topicServer2;
public static void init() {
ClusterManager cluster = new ClusterManager();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("127.0.0.1:5701");
HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient(config);
topicServer2 = hazelcastClient.getTopic("server2");
topicServer2.addMessageListener(cluster);
topicServer1 = hazelcastClient.getTopic("server1");
topicServer1.publish("this is test msg from Server1");
}
@Override
public void onMessage(Message message) {
String data = (String) message.getMessageObject();
Debug.trace("onMessage", data);
topicLobby.publish("this is test msg from Server2");
}
}
在server2上,我有:
public class ClusterManager implements MessageListener {
static ITopic topicServer1;
static ITopic topicServer2;
public static void init() {
ClusterManager cluster = new ClusterManager();
ClientConfig config = new ClientConfig();
config.getNetworkConfig().addAddress("127.0.0.1:5701");
HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient(config);
topicServer1 = hazelcastClient.getTopic("server1");
topicServer1.addMessageListener(cluster);
topicServer2 = hazelcastClient.getTopic("server2");
topicServer2.publish("this is test msg from Server2");
}
@Override
public void onMessage(Message message) {
String data = (String) message.getMessageObject();
Debug.trace("onMessage", data);
topicLobby.publish("this is test msg from Server1");
}
}
但是当我运行2台服务器时,CPU使用率非常高。 在这种情况下使用淡褐色的正确方法是什么?
由于