twitter4j在运行storm拓扑时抛出java.lang.reflect.invocationtargetexception

wr98u20j  于 2021-06-21  发布在  Storm
关注(0)|答案(0)|浏览(311)

嗨,我正在尝试运行一个简单的拓扑,从twitter获取tweet,然后将tweet和作者写入文本文件。下面是我用来做喷口的代码:
简单双排口:

public class SimpleTweetFeed extends BaseRichSpout {

private final String accessToken;
private final String accessTokenSecret;
private final String consumerKey;
private final String consumerKeySecret;

private SpoutOutputCollector spoutOutputCollector;
private TwitterStream twitterStream;
private LinkedBlockingQueue<Status>statuses;
private FilterQuery filterQuery;

public SimpleTweetFeed(String accessToken,String accessTokenSecret,String consumerKey,String consumerKeySecret){
    if(accessToken==null || accessTokenSecret==null || consumerKey==null || consumerKeySecret==null){
        throw new RuntimeException(Twitter4j OAuth Field cannot be null");
    }

    this.accessToken=accessToken;
    this.accessTokenSecret=accessTokenSecret;
    this.consumerKey=consumerKey;
    this.consumerKeySecret=consumerKeySecret;

}

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("STATUS", "USERNAME"));
}

public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    statuses=new LinkedBlockingQueue<Status>();
    spoutOutputCollector=collector;
    ConfigurationBuilder configurationBuilder=new ConfigurationBuilder();
    configurationBuilder.setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerKeySecret);

    twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance();

    twitterStream.addListener(new StatusListener() {
        @Override
        public void onStatus(Status status) {
            statuses.offer(status);
        }
        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }
        @Override 
        public void onTrackLimitationNotice(int i) {

        }
        @Override
        public void onScrubGeo(long l, long l1) {

        }
        @Override
        public void onStallWarning(StallWarning stallWarning) {

        }
        @Override
        public void onException(Exception e) {

        }
    });

    filterQuery = new FilterQuery();

    if (filterQuery == null) {
        twitterStream.sample();
    } else {
        twitterStream.filter(filterQuery);
    }

}
@Override
public void nextTuple() {
    //emit tweets
    Status status=(Status)statuses.poll();
    if(status==null){
        Utils.sleep(1000);
    }else{
        spoutOutputCollector.emit(new Values(status,status.getUser().getScreenName()));
    }
}

@Override
public void close() {
    twitterStream.shutdown();
    super.close();
}

}
但是,无论何时运行拓扑,都会引发以下异常:

java.lang.AssertionError: java.lang.reflect.InvocationTargetException
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:76) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.TwitterStreamFactory.<clinit>(TwitterStreamFactory.java:40) ~[twitter4j-stream-3.0.3.jar:3.0.3]
at storm.starter.spout.TwitterSampleSpout.open(TwitterSampleSpout.java:106) ~[storm-starter-0.9.5.jar:0.9.5]
at backtype.storm.daemon.executor$fn__3371$fn__3386.invoke(executor.clj:522) ~[storm-core-0.9.5.jar:0.9.5]
at backtype.storm.util$async_loop$fn__460.invoke(util.clj:461) ~[storm-core-0.9.5.jar:0.9.5]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_80]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_80]
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:70) ~[twitter4j-core-3.0.3.jar:3.0.3]
... 6 common frames omitted
Caused by: java.lang.NoSuchFieldError: factory
at twitter4j.AppEngineTwitterImpl.setFactory(AppEngineTwitterImpl.java:35) ~[twitter4j-appengine-4.0.2.jar:3.0.3]
at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:77) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:54) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.AppEngineTwitterImpl.<init>(AppEngineTwitterImpl.java:30) ~[twitter4j-appengine-4.0.2.jar:3.0.3]
... 11 common frames omitted
9008 [Thread-9-TWITTER_SPOUT] ERROR backtype.storm.daemon.executor - 
java.lang.AssertionError: java.lang.reflect.InvocationTargetException
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:76) ~[twitter4j-   core-3.0.3.jar:3.0.3]
at twitter4j.TwitterStreamFactory.<clinit>(TwitterStreamFactory.java:40) ~[twitter4j-stream-3.0.3.jar:3.0.3]
at storm.starter.spout.TwitterSampleSpout.open(TwitterSampleSpout.java:106) ~[storm-starter-0.9.5.jar:0.9.5]
at backtype.storm.daemon.executor$fn__3371$fn__3386.invoke(executor.clj:522) ~[storm-core-0.9.5.jar:0.9.5]
at backtype.storm.util$async_loop$fn__460.invoke(util.clj:461) ~[storm-core-0.9.5.jar:0.9.5]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_80]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_80]
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_80]
at twitter4j.TwitterFactory.<clinit>(TwitterFactory.java:70) ~[twitter4j-core-3.0.3.jar:3.0.3]
... 6 common frames omitted
Caused by: java.lang.NoSuchFieldError: factory
at twitter4j.AppEngineTwitterImpl.setFactory(AppEngineTwitterImpl.java:35) ~[twitter4j-appengine-4.0.2.jar:3.0.3]
at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:77) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:54) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51) ~[twitter4j-core-3.0.3.jar:3.0.3]
at twitter4j.AppEngineTwitterImpl.<init>(AppEngineTwitterImpl.java:30) ~[twitter4j-appengine-4.0.2.jar:3.0.3]
... 11 common frames omitted
9084 [Thread-9-TWITTER_SPOUT] ERROR backtype.storm.util - Halting process: ("Worker died")
java.lang.RuntimeException: ("Worker died")
at backtype.storm.util$exit_process_BANG_.doInvoke(util.clj:325) [storm-core-0.9.5.jar:0.9.5]
at clojure.lang.RestFn.invoke(RestFn.java:423) [clojure-1.5.1.jar:na]
at backtype.storm.daemon.worker$fn__4694$fn__4695.invoke(worker.clj:493) [storm-core-0.9.5.jar:0.9.5]
at backtype.storm.daemon.executor$mk_executor_data$fn__3272$fn__3273.invoke(executor.clj:240) [storm-core-0.9.5.jar:0.9.5]
at backtype.storm.util$async_loop$fn__460.invoke(util.clj:473) [storm-core-0.9.5.jar:0.9.5]
at clojure.lang.AFn.run(AFn.java:24) [clojure-1.5.1.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]

对上述例外情况的处理有何建议?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题