问题
I've written simple test for using JGroups. There are two simple applications like this
import org.jgroups.*;
import org.jgroups.conf.ConfiguratorFactory;
import org.jgroups.conf.ProtocolConfiguration;
import org.jgroups.conf.ProtocolStackConfigurator;
import java.util.List;
/**
* @author Sergii.Zagriichuk
*/
public class Test {
public static void main(String[] args) throws Exception {
JChannel ch = new JChannel();
ch.setReceiver(new ReceiverAdapter() {
public void receive(Message msg) {
System.out.println("received message " + msg.getObject());
}
});
ch.connect("one");
}
}
and this
package com.datacradle.example;
import org.jgroups.Global;
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.conf.ConfiguratorFactory;
import org.jgroups.conf.ProtocolConfiguration;
import org.jgroups.conf.ProtocolStackConfigurator;
import org.jgroups.stack.IpAddress;
import org.jgroups.util.SingletonAddress;
import org.jgroups.util.Util;
import java.util.List;
/**
* @author Sergii.Zagriichuk
*/
public class Test {
void start(String props) throws Exception {
JChannel chanel = new JChannel();
String line = "Test message";
chanel.connect("one");
// Message msg = new Message(null, null, new TestData(line, 1111, line + " Test suffix"));
Message msg = new Message(new IpAddress("fe33:0:0:0:1986:ba23:d939:f226%12",55435) , null, new TestData(line,1111,line+" sdfasdfasdfasdfasdfa"));
chanel.send(msg);
}
public static void main(final String[] args) throws Exception {
new Test().start(null);
}
}
So, If I use this style for creating message
Message msg = new Message(null, null, new TestData(line, 1111, line + " Test suffix"));
I will receive just a one message(this is for all subscribers in current group), but if I use this style
Message msg = new Message(new IpAddress("fe33:0:0:0:1986:ba23:d939:f226%12",55435) , null, new TestData(line,1111,line+" sdfasdfasdfasdfasdfa"));
I will receive a lot of messages like in a loop (this is for one dist address) What is the problem or I should added some additional parameters?
P.S, JGroups 3.0.0 RC1
Thanks.
回答1:
You should not create a member address using the IpAddress class, as this is something that's opaque. I suggest fetch the target address from a view, e.g.
List<Address> members=channel.getView().getMembers();
Address target=members.get(0);
Message msg=new Message(target, null, "hello");
channel.send(msg);
来源:https://stackoverflow.com/questions/7585958/jgroups-sendnull-null-messagevs-sendaddress-null-message