JGroups:发送(null,null,消息)与发送(地址,null,消息)

发布于 2024-12-07 04:20:18 字数 2160 浏览 1 评论 0原文

我已经编写了使用 JGroups 的简单测试。 有两个像这样

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

和这样的

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

简单应用程序所以,如果我使用这种样式创建消息,

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

我会收到很多消息,就像循环一样(这是针对一个 dist 地址) 有什么问题或者我应该添加一些额外的参数?

PS,JGroups 3.0.0 RC1

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜无邪 2024-12-14 04:20:18

您不应该使用 IpAddress 类创建成员地址,因为这是不透明的。我建议从视图中获取目标地址,例如

List<Address> members=channel.getView().getMembers();
Address target=members.get(0);
Message msg=new Message(target, null, "hello");
channel.send(msg);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文