我是akka的新手,所以想问一下如何将事件添加到事件总线并捕获它。有代码示例。
localEventBus = new com.google.common.eventbus.EventBus(new ExceptionHandler());
Object listener = new Object()
{
@Subscribe
public void witingCommand(SomeCommand cmd)
{
//Here I want to catch call
}
};
...
localEventBus.register(listener);
...
client = system.actorOf(Props.create(ClientActor.class, localEventBus, receptionists));
...
client.tell(new Publish(Constants.COMMAND, someCommand), noSender());
类型:
private final ActorSystem system;
private ActorRef client;
ClientActor.java
final class ClientActor extends UntypedActor
{
ClientActor(final EventBus eventBus, final List<ActorSelection> receptionists)
{
localEventBus = eventBus;
clusterReceptionists.addAll(receptionists);
}
@Override
public void preStart()
{...}
@Override
public void postStop()
{...}
@Override
public void onReceive(final Object msg)
{...}
}
问题是没有调用“witingCommand”,也许有人可以告诉我我做错了什么?