1

I'm having trouble figuring how to deal with disconnections with hbc twitter api. The doc says I need slow down reconnect attempts according to the type of error experienced. Where do I get the type of error experienced? Is it in the msgQueue or the eventQueue or wherever?

@Asynchronous
@Override
public void makeLatestsTweets() {

    msgList = new LinkedList<Tweet>();

    BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100);
    BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(100);


    Hosts hosebirdHosts = new HttpHosts(Constants.SITESTREAM_HOST);

    StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

    userIds = addFollowings();

    hosebirdEndpoint.followings(userIds);

    Authentication hosebirdAuth = new OAuth1(CONSUMER_KEY, CONSUMER_SECRET,
            TOKEN, SECRET);

    ClientBuilder builder = new ClientBuilder().hosts(hosebirdHosts)
            .authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
            .processor(new StringDelimitedProcessor(msgQueue))
            .eventMessageQueue(eventQueue);

    Client hosebirdClient = builder.build();
    hosebirdClient.connect();
    while (!hosebirdClient.isDone()) {
        try {
            String msg = msgQueue.take();
            Tweet tweet = format(msg);
            if (tweet != null) {
                System.out.println(tweet.getTweetsContent());
                msgList.addFirst(tweet);
                if (msgList.size() > tweetListSize) {
                    msgList.removeLast();
                }
                caller.setMsgList(msgList);
            }
        } catch (InterruptedException e) {
            hosebirdClient.stop();
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
Ced
  • 15,847
  • 14
  • 87
  • 146
  • It's been some time since I don't use `hbc` but if I remember the library reconnects by itself -i.e. you don't see the error at this level. Can you post the link to the document in which they talk about "slowing down"? They might refer to Twitter actually denying access to your user if you are doing things too fast; anyhow I can tell you if you have just one process (using `hbc` or any other library) you can reconnect as many times as you like. Maybe if you have several processes in parallel you face other problems. Hope it helps. – lrnzcig Oct 08 '15 at 14:31
  • @lrnzcig here : https://dev.twitter.com/streaming/overview/connecting at the point called "reconnecting". – Ced Oct 08 '15 at 16:36
  • Ok. I thought you had seen it in the `hbc` documentation, and indeed it didn't make sense to me. But indeed in twitter's page. Then (1) in my experience, but only with one process (and not using `hbc`), I've been just reconnecting immediately with no big issues, and (2) in `hbc`, if I remember well, you don't handle the reconnection at the high level. You should modify code in the library if you want to handle those. Should not be difficult to find though. – lrnzcig Oct 08 '15 at 16:52
  • @lrnzcig Thanks, so in your case you just called `hosebirdClient.connect();` when `hosebirdClient.isDone()` ? – Ced Oct 08 '15 at 17:02
  • I've checked my code to try to remember... it's actually very similar to yours. My point is that the library `hbc` itself handles the reconnection, as far as I remembered. Just to be sure, I've just done a quick trial: started the client, unplugged the ethernet cable, and plug it again, and it took some time (1 minute) but the client reconnected by itself. And I was trying to say that, if you're having issues and you want to change the behavior, you will have to change the client... But it would not be too difficult to find I think. – lrnzcig Oct 08 '15 at 17:18

0 Answers0