我通过 jgroups 建立了一个集群的连接器。我的连接器实例在同一台机器上运行时确实可以正常工作并收到其他消息,但是当它们在两台不同的机器上运行时它们不会捕获其他消息。我的 JGroups 连接器类:
public class JGroupsMulticastConnector implements Sender, Listener {
JChannel basicChannel = null;
String clusterName = "";
public JGroupsMulticastConnector( String clusterName) {
this.clusterName = clusterName;
try {
basicChannel = new JChannel();
} catch (Exception e) {
MyLogger.error(e, name);
}
}
public void init() {
try {
basicChannel.connect(clusterName);
basicChannel.setReceiver(new ReceiverAdapter(){
@Override
public void receive(org.jgroups.Message msg) {
System.out.println(name+":"+"Got a Message");
super.receive(msg);
}
});
} catch (Exception e) {
MyLogger.error(e, name);
}
}
public void shutdown() {
basicChannel.disconnect();
}
@Override
public void send(Message msg) {
basicChannel.send(msg);
}
}