我正在尝试实施一个基本的1喷口 - 1螺栓风暴拓扑。我有一个Storm Bolt使用Apache HttpClient(4.3.1)发出HTTP请求。但是,当我运行它时,我得到以下异常:
[main] ERROR org.apache.zookeeper.server.NIOServerCnxn - Thread Thread[main,5,main] died
java.lang.RuntimeException: java.io.NotSerializableException: org.apache.http.impl.client.InternalHttpClient
at backtype.storm.utils.Utils.serialize(Utils.java:56)
at backtype.storm.topology.TopologyBuilder.createTopology(TopologyBuilder.java:89)
at app.storm.StormTopology.main(StormTopology.java:26)
Caused by: java.io.NotSerializableException: org.apache.http.impl.client.InternalHttpClient
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at backtype.storm.utils.Utils.serialize(Utils.java:52)
... 2 more
其他人见过这个?我知道Storm本身在内部使用HTTP Client(4.1.1)。我试图用4.3.1版本替换内部库,我得到了另一个错误:
Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:487)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:147)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:136)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:112)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:727)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:58)
at app.storm.bolts.DataFetcherBolt.<init>(DataFetcherBolt.java:34)
at app.storm.StormTopology.main(StormTopology.java:18)
答案 0 :(得分:6)
我从Google风暴论坛项目得到了答案。以下是该帖子的链接:
https://groups.google.com/forum/#!topic/storm-user/vdfamKeR9Lk
修复是在Bolt类的prepare方法中实例化HttpClient实例。