Question

I made a connector to a cluster by jgroups. My instances of connectors do work right and get others messages when they are running on a same machine, but they do not catch others messages when they are running on tow different machines. My JGroups Connector class:

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);
    }

}
Was it helpful?

Solution

If it works on the same machine, your code is fine. Very likely the problem is with discovery - nodes do not find each other.

Look at your configured stack and check what discovery protocol you are using. If you are using TCPPING (http://www.jgroups.org/javadoc/org/jgroups/protocols/TCPPING.html) you need to reconfigure the IP addresses of the nodes.

Most likely, it will be MPING (http://www.jgroups.org/javadoc/org/jgroups/protocols/MPING.html) which uses multicast to discover nodes. Make sure multicast messages are being sent inbetween these nodes. Typically, firewalls drop this multicast communication (you can temporarily turn off firewall to test).

Also, check that your network components are not dropping multicast communication.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top