我使用风暴本地模式没问题,但是会在集群上报告故障。引起:java.lang.RuntimeException: java.io.NotSerializableException: io.netty.channel.DefaultChannelHandlerContext at org.apache.storm.serialization.SerializableSerializer.write(SerializableSerializer.java:41) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:628) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:113) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:39) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:628) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.serializers.CollectionSerializer.write(CollectionSerializer.java:100) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.serializers.CollectionSerializer.write(CollectionSerializer.java:40) 〜[kryo-3.0.3.jar:?] at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:534) 〜[kryo-3.0.3.jar:?] at org.apache.storm.serialization.KryoValuesSerializer.serializeInto(KryoValuesSerializer.java:44) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at org.apache.storm.serialization.KryoTupleSerializer.serialize(KryoTupleSerializer.java:44) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at org.apache.storm.daemon.worker $ mk_transfer_fn $ transfer_fn__6723.invoke(worker.clj:192) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at org.apache.storm.daemon.executor $ start_batch_transfer__GT_worker_handler_BANG_ $ fn__6411.invoke(executor.clj:313) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at org.apache.storm.disruptor $ clojure_handler $ reify__6005.onEvent(disruptor.clj:40) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] at org.apache.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:451) 〜[storm-core-1.0.1.2.5.0.0-1245.jar:1.0.1.2.5.0.0-1245] ... 6更多
这是我的代码:
public class NettySpout extends BaseRichSpout {
private static final long serialVersionUID = 1L;
/**
* colloctor for spout
*/
private SpoutOutputCollector collector;
@Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
collector=spoutOutputCollector;
StormServer stormServer=new StormServer();
stormServer.run();
}
@Override
public void nextTuple() {
Values tuple;
try {
while ((tuple = ServerHandler.queue.take()) != null) {
collector.emit(tuple);
}
} catch (Exception e) {
}
}
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declare(new Fields("value","channl"));
}
public class ServerHandler extends ChannelInboundHandlerAdapter{
private static Logger logger = LogManager.getLogger(ServerHandler.class);
public static LinkedBlockingQueue<Values> queue = new LinkedBlockingQueue<Values>();
public static Map<String,ChannelHandlerContext> ctxes;
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
JSONObject message = (JSONObject) msg;
queue.put(new Values(new StreamData(message.toString().getBytes()), new HashMap<>(ctxes)));
}
答案 0 :(得分:1)
我对风暴本身并不了解,但似乎你试图将ChannelHandlerContext(存储在你的Map中)序列化,而不是Serializable。