<config xmlns="urn:org:jgroups"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:org:jgroups
http://www.jgroups.org/schema/jgroups-4.2.xsd">
<TCP bind_port="7800" />
<TCPPING timeout="3000" initial_hosts="host1[7800],host2[7800],host3[7800]" />
<MERGE2 />
<FD_SOCK />
<FD timeout="5000" max_tries="5" />
<VERIFY_SUSPECT />
<BARRIER />
<pbcast.NAKACK2 use_mcast_xmit="false" discard_delivered_msgs="true" />
<UNICAST />
<pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="4M" />
<pbcast.GMS print_local_addr="true" join_timeout="2000"/>
<UFC />
<MFC />
<FRAG2 frag_size="60000" />
<RSVP />
</config>
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
public class JGroupsExample extends ReceiverAdapter {
private JChannel channel;
public static void main(String[] args) throws Exception {
JGroupsExample example = new JGroupsExample();
example.start();
example.send("Hello, JGroups!");
Thread.sleep(1000);
example.stop();
}
public void start() throws Exception {
channel = new JChannel("jgroups-config.xml");
channel.setReceiver(this);
channel.connect("myCluster");
}
public void stop() {
channel.close();
}
public void send(String message) throws Exception {
channel.send(new Message(null, null, message));
}
@Override
public void receive(Message message) {
System.out.println("Received message: " + message.getObject());
}
}