Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use okhttp-sse and drop jersey dependency #147

Merged
merged 16 commits into from Dec 6, 2018
Merged

use okhttp-sse and drop jersey dependency #147

merged 16 commits into from Dec 6, 2018

Conversation

jillesvangurp
Copy link
Contributor

Fixes #141

  • drops jersey support
  • adds okhttp-sse instead
  • reimplements streaming using that
  • new streaming methods return the okhttp-sse of EventSource

@jillesvangurp
Copy link
Contributor Author

This is still WIP, tests are missing (there was no test coverage for the old methods either). So, please help test and review. I'll do that as well. Meanwhile, please review the changes.

Another issue is that some of the implementations I adapted looked like they were copy pasted and possibly wrong. E.g. PaymentsRequestBuilder was streaming OperationsResponse instead of PaymentOperationsResponse. I've not changed that and left it as it was.

@bartekn it may be a good idea to use docker-compose to launch a standalone chain and run some integration tests against that. I've done this for my kotlin wrapper.

See here for an example:
https://github.com/Inbot/inbot-stellar-kotlin-wrapper/blob/master/build.gradle#L105

This would require enabling docker support on travis. It's been a while since I did that but should be possible as well.

Alternatively, we can write a simple test and point it at horizon testnet. Should be OK as long as it doesn't run too often.

@jillesvangurp
Copy link
Contributor Author

Sadly does not yet work. Horizon is returning a mimetype of (application/hal+json; charset=utf-8) that okhttp-sse does not like. It seems to check for text/eventstream

This API is marked as experimental on the okhttp side. I'll see if I can workaround this in some way.

@bartekn
Copy link
Contributor

bartekn commented Oct 26, 2018

Sadly does not yet work. Horizon is returning a mimetype of (application/hal+json; charset=utf-8) that okhttp-sse does not like. It seems to check for text/eventstream

It returns the Content-Type: text/evenstream header, you can easily check it like:

curl -v -H "Accept: text/event-stream" "https://horizon-testnet.stellar.org/ledgers?cursor=now"

However, Horizon requires Accept: text/event-stream request header to start a streaming connection.

@jillesvangurp
Copy link
Contributor Author

@bartekn I have a working version now. Turns out you have to manually set the header on the request with okhttp-sse.

A few changes:

  • I've implemented an SSEManager class that orchestrates the reconnecting and stopping logic.
  • There's a very simplistic test that verifies stuff streams from horizon. It's ignored by default to prevent needless API calls/running into rate limits: org.stellar.sdk.StreamingSmokeTest#shouldStreamPaymentsFromTestNet

From my point of view this seems kind of a convoluted pattern; but it works. The alternative of simply paging normal API requests and keeping track of the cursor would be about as complicated. This is actually what I implemented in out kotlin wrapper. Very straightforward to do with kotlin sequences.

Another issue is that running background threads pretty much is a bad idea on Android.

Let me know if you like this approach or if you would like changes to this.

- Merge SSEUtils and SSEManager classes into a SSEStream class
- track pagingToken via an atomic reference
- tighten API by making most methods private/package protected
- misc refactoring/renames
@jillesvangurp
Copy link
Contributor Author

@bartekn Thanks for your review. I updated the PR and refactored a bit. There is now just one SSEStream class and most methods on it are private.

handle goodbye event
use lock to prevent edge case of restarting after calling close
@jillesvangurp
Copy link
Contributor Author

@bartekn addressed your comments, have another look please.

@cyberluke
Copy link

@bartekn It was 21 days. Can you review please? You get what you want after one day, but then nothing happens. 8 days ago I post about streaming issue, which is not working in your official sdk on StackExchange: https://stellar.stackexchange.com/questions/1945/subscribing-to-incoming-transaction-does-not-work ...now I tried this and this solves the streaming issue, it should be in main already. The person sent this pull request is highly skilled, he deserves more support.

@bartekn bartekn merged commit 198cab5 into lightsail-network:master Dec 6, 2018
@bartekn
Copy link
Contributor

bartekn commented Dec 6, 2018

Many thanks for this @jillesvangurp and sorry for a delay once again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants