Skip to content

Example using streaming #1054

@snicoll

Description

@snicoll

I am trying to get my head around why my code does not work when I try to use an async client (Apache) while the JDK works fine.

My use case is connecting to the Twitter stream endpoint. There's already such a client and it doesn't work with an async client (https://github.com/redouane59/twittered) either.

The code is here https://github.com/redouane59/twittered/blob/19134de9dc9ae82be1b61ac551c6a482a04017ab/src/main/java/io/github/redouane59/twitter/helpers/RequestHelperV2.java#L99

With the default JDK client, all is fine. With the Apache one, the callback is never invoked (neither the onCompleted or the onError). However, if I enable the logging of the client, I can see the connection is established and the stream is being consumed.

Example usage with Twittered:

ApacheHttpClient httpClient = new ApacheHttpClient(HttpAsyncClientBuilder.create()
        .setDefaultRequestConfig(RequestConfig.custom()
                .setCookieSpec(CookieSpecs.STANDARD)
                .setSocketTimeout((int) Duration.ofSeconds(30).toMillis()).build()));
TwitterClient twitterClient = new TwitterClient(credentials, httpClient);
System.out.println("Initiate stream");
twitterClient.startFilteredStream((tweet) -> System.out.println(tweet.getText()));

If I use the default (JDK) client, the callback is invoked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions