- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
订阅者的主类:Application.java
package com.mynamespace;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.contrib.pattern.DistributedPubSubExtension;
import akka.contrib.pattern.DistributedPubSubMediator;
import com.mynamespace.actors.SubscriberActor;
@SpringBootApplication
@ComponentScan(basePackages = "com.mynamespace.*")
public class Application {
public static void main(String[] args) throws InterruptedException {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
// get hold of the actor system
ActorSystem system = ctx.getBean(ActorSystem.class);
ActorRef mediator = DistributedPubSubExtension.get(system).mediator();
ActorRef subscriber = system.actorOf(
Props.create(SubscriberActor.class), "subscriber");
// subscribe to the topic named "content"
mediator.tell(new DistributedPubSubMediator.Put(subscriber), subscriber);
// subscriber.tell("init", null);
System.out.println("Running.");
Thread.sleep(5000l);
}
}
订阅者 Actor :SubscriberActor.java
package com.mynamespace.actors;
import java.util.ArrayList;
import java.util.List;
import akka.actor.UntypedActor;
import com.mynamespace.message.CategoryServiceRequest;
import com.mynamespace.message.CategoryServiceResponse;
public class SubscriberActor extends UntypedActor {
@Override
public void onReceive(Object msg) throws Exception {
if (msg instanceof CategoryServiceRequest) {
System.out.println("Request received for GetCategories.");
CategoryServiceResponse response = new CategoryServiceResponse();
List<String> categories = new ArrayList<>();
categories.add("Food");
categories.add("Fruits");
response.setCatgories(categories);
getSender().tell(response, getSelf());
} else if (msg instanceof String && msg.equals("init")) {
System.out.println("init called");
} else {
System.out
.println("Unhandelled message received for getCategories.");
}
}
}
订阅者的Application.conf
akka {
loglevel = INFO
stdout-loglevel = INFO
loggers = ["akka.event.slf4j.Slf4jLogger"]
extensions = ["akka.contrib.pattern.DistributedPubSubExtension"]
actor {
provider = "akka.cluster.ClusterActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
seed-nodes = [
"akka.tcp://mynamespace-actor-system@127.0.0.1:2551",
"akka.tcp://mynamespace-actor-system@127.0.0.1:2552"]
auto-down-unreachable-after = 10s
}
}
发布者的主类:Application.java
package com.mynamespace;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.contrib.pattern.DistributedPubSubExtension;
import akka.contrib.pattern.DistributedPubSubMediator;
import com.mynamespace.actors.PublisherActor;
@SpringBootApplication
@ComponentScan(basePackages = "com.mynamespace.*")
public class Application {
public static void main(String[] args) throws InterruptedException {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
// get hold of the actor system
ActorSystem system = ctx.getBean(ActorSystem.class);
ActorRef mediator = DistributedPubSubExtension.get(system).mediator();
ActorRef publisher = system.actorOf(Props.create(PublisherActor.class),
"publisher");
mediator.tell(new DistributedPubSubMediator.Put(publisher), publisher);
Thread.sleep(5000);
publisher.tell("hi", publisher);
System.out.println("Running.");
}
}
PublisherActor.java
package com.mynamespace.actors;
import scala.concurrent.Future;
import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.contrib.pattern.DistributedPubSubExtension;
import akka.contrib.pattern.DistributedPubSubMediator;
import akka.dispatch.Mapper;
import akka.pattern.Patterns;
import akka.util.Timeout;
import com.mynamespace.message.CategoryServiceRequest;
import com.mynamespace.message.CategoryServiceResponse;
public class PublisherActor extends UntypedActor {
// activate the extension
ActorRef mediator = DistributedPubSubExtension.get(getContext().system())
.mediator();
public void onReceive(Object msg) {
if (msg instanceof String) {
Timeout timeOut = new Timeout(50000l);
mediator.tell(new DistributedPubSubMediator.Send(
"/user/subscriber", new CategoryServiceRequest()),
getSelf());
Future<Object> response = Patterns.ask(mediator,
new DistributedPubSubMediator.Send("/user/subscriber",
new CategoryServiceRequest()), timeOut);
Future<CategoryServiceResponse> finalresponse = response.map(
new Mapper<Object, CategoryServiceResponse>() {
@Override
public CategoryServiceResponse apply(Object parameter) {
CategoryServiceResponse responseFromRemote = (CategoryServiceResponse) parameter;
System.out.println("received:: list of size:: "
+ responseFromRemote.getCatgories().size());
return responseFromRemote;
}
}, getContext().system().dispatcher());
} else if (msg instanceof DistributedPubSubMediator.SubscribeAck) {
System.out.println("subscribbed.......");
} else {
unhandled(msg);
}
}
}
发布者的应用程序配置与订阅者的相同。两者都在同一系统的不同端口上运行。
我在本地系统上定义并运行了两个种子节点。不知何故,我无法通过 DistributedPubSub 调解器向生产者(均在不同节点上运行)询问/告知订阅者。
在运行 Subscriber 然后是 publisher 之后:我没有在 stdout/logs 中打印任何异常或任何死信引用。
是否可以查看我的调解员持有哪些 Actor 引用资料?
需要帮助来发现问题或可能的问题。
最佳答案
我遇到了同样的问题,在@spam 的评论和我自己的实验之后,我可以推荐的是对组使用发布/订阅和 sendOneMessageToEachGroup=true
。
是否假设 Send 仅在本地有效?如果是这样,文档没有明确说明。但我也可以通过那里的代码看出文档的这个特定部分显然被忽略了(如更改类名但不调用那些,调用前面示例中的前面的)
希望这对遇到此问题的任何人有所帮助,因为文档显然有点误导
关于java - Akka 分布式 pub sub : Java implementation not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536080/
Rust 支持 pub和 pub(super) . pub使父模块可以访问项目...和pub(super)似乎也做同样的事情。我试过玩下面的例子,并交换 pub和 pub(super)似乎没有效果:
我正在尝试运行 this拖放 API。当我尝试运行 dart 文件(使用 dart 编辑器)时,出现以下错误: could not start pub serve or connect to pub
根据pub get docs pub get 和 pub Upgrade 之间的主要区别是: If a lockfile already exists, pub get uses the versio
我see函数的可见性可以在模块内声明为 pub(self)。这与没有 pub 属性的私有(private)函数有何不同?如果它们没有区别,为什么会存在这种语法? 最佳答案 pub(restricted
我正在运行 pub install 以便我可以使用作为 dart sdk 一部分的 intl 包(我需要使用 DateFormat 类)。我已经在我的项目中安装了其他包,例如 XML 解析器和演示文稿
假设我在 Rust 包中有这个文件层次结构: src/... src/m1/mod.rs src/m1/path/m2.rs 拥有以下行的实际区别是什么: pub mod path::m2; 在我的文
其中一个比另一个更安全吗? 最佳答案 id_rsa.pub 和 id_dsa.pub 是 id_rsa 和 id_dsa 的公钥。 如果您询问与 SSH 相关的问题,id_rsa 是 RSA key
pub 是 Dart 的包管理器。 Flutter 是一个使用 Dart 的移动应用 SDK。如何创建依赖于或以 Flutter 为目标的包? 最佳答案 要从 pub 包中声明对 Flutter 的依
id_rsa.pub 文件基本上是 Linux 主文件夹下 .ssh 文件夹中的一些加密文本,用于公钥加密。它使用 .pub 文件格式。但为什么这种文件格式也恰好是 Microsoft Publish
使用当前版本的angular.dart.tutorial , 使用 Chapter_04 对于“pub serve”,main.dart.js 是一个 42337 行的文件,示例运行良好。 对于“pu
假设我正在运行我自己的 pub-dartlang 实例对于私有(private)酒吧供稿;如何在 pubspec.yaml 中注明哪些软件包来自私有(private)提要与 pub.dartlang.
我们通过运行脚本来实现DART自动化,该脚本导航到项目文件夹(.yaml文件所在的位置)并运行“pub get”和“pub build”。它工作了一段时间,但现在(两种情况下)我们都得到了: Unha
我刚刚安装了 Dart Editor 并创建了一个简单的 Web 应用程序,当我单击运行时它显示此错误并且没有任何 react 。 “无法启动 pub 服务或连接到 pub” dart editor
当我尝试在 android studio 中打开大部分已下载的 flutter 应用程序时,它一直告诉我“Pub get”尚未运行,当我按下“获取依赖项”或升级依赖项时,它会向我显示该错误。我已经把a
在哪里可以找到用于搜索和列出已安装的打包版本和可用升级版本的命令行工具? 我想不出任何其他的软件包管理工具,它们不包含列出已安装版本或查找可用升级的命令,而无需实际升级。 例如,如果我的pubspec
前两天升级到 Flutter 2.0 开始面对 Execution failed for task ':app:compileFlutterBuildDebug'由于一些包裹。 然后我降级了,但错误仍
下面提供了相关的程序代码。我经常在开源项目中看到这样的代码,可以在Linux和Windows上运行。有人告诉我,这是为了避免编译警告。真的是这样吗? class Base { public:
我有一个带有简单测试代码的函数,例如: exports.helloPubSub = (event, context) => { const message = event.data
无法解析 URL“https://pub.dartlang.org”。错误 (69):无法“发布升级”flutter 工具。五秒后重试...(还剩 9 次尝试) 这是我创建或升级flutter时flu
我正在尝试制作一个脚本来控制农场中的 Android 设备,adb connect 通过 OpenSTF 建立连接。 .设备接受来自客户端的连接的要求之一是在 OpenSTF 中提供 adbkey.p
我是一名优秀的程序员,十分优秀!