gpt4 book ai didi

java - JGroups:发送(空,空,消息)与发送(地址,空,消息)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:00:31 28 4
gpt4 key购买 nike

我已经为使用 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 地址)有什么问题还是我应该添加一些额外的参数?

附言,JGroups 3.0.0 RC1

谢谢。

最佳答案

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

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

关于java - JGroups:发送(空,空,消息)与发送(地址,空,消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7585958/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com