我正在使用 twitter HBC 在多线程环境中使用Twitter过滤器流的用例。
我收到关键字,用于根据我收到的每个请求跟踪用户,处理它们并将它们保存到数据库中。 示例
我目前正在做的是,为每个请求打开一个新线程并处理它们。
我正在为下面的每个终点(I am following this official HBC example)
建立连接endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo"));
Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
// Create a new BasicClient. By default gzip is enabled.
Client client = new ClientBuilder()
.hosts(Constants.STREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Establish a connection
client.connect();
The problem that I am facing is twitter gives me warning of having more that one connection.
但是根据上面的代码和我的用例我必须创建Client
对象的新实例,以便我收到作为我的终点的请求
(trackTerms)对于我收到的每个请求都是不同的。。
为了我的用例(多线程系统)连接到twitter的正确方法是什么,以避免to many connections warning
和rate limit warnings
来自twitter的当前警告:
2017-02-01 13:47:33 INFO TwitterStreamImpl:62 - 420:Returned by the Search and Trends API when you are being rate limited (https://dev.twitter.com/docs/rate-limiting).
Returned by the Streaming API:
Too many login attempts in a short period of time.
Running too many copies of the same application authenticating with the same account name.
Exceeded connection limit for user
感谢。