以下代码构建一个以喷口开始的拓扑。在此,TenderEventSpout2
是一个Akka演员。带Akka Actors的Storm拓扑生成器
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("EventSpout", new TenderEventSpout2(), 1);
TenderEventSpout2看起来是这样的:
public class TenderEventSpout2 extends UntypedActor implements IRichSpout{
@Override
public void onReceive(Object message){// throws IOException {}
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {}
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {}
@Override
public void nextTuple() {}
//Override all the interface methods
@Override
public void close() {}
public boolean isDistributed() {
return false;
}
@Override
public void activate() {}
@Override
public void deactivate() {}
@Override
public void ack(Object msgId) {}
@Override
public void fail(Object msgId) {}
@Override
public Map<String, Object> getComponentConfiguration() {
return null;
}
}
这编译成功,但我得到这个错误:
You cannot create an instance of [org.quadrisk.toplogy.TenderEventSpout2] explicitly using the constructor (new). You have to use one of the 'actorOf' factory methods to create a new actor. See the documentation.
但是创建使用actorOf一个演员的建议将返回我的目标ActorRef类型。我该如何解决这个问题。提前致谢。
我不确定..你试过简单的演员吗?如果演员不工作,您可以使用两个类而不是一个,并向您的喷口类中添加一个“ActorRef”成员变量。 –
@ MatthiasJ.Sax简单的投射不起作用。所以遵循你的第二个建议。有用 ! –