{"id":18542160,"url":"https://github.com/heremaps/oksse","last_synced_at":"2025-08-20T20:32:34.041Z","repository":{"id":71903527,"uuid":"98971303","full_name":"heremaps/oksse","owner":"heremaps","description":"An extension library for OkHttp to create a Server-Sent Event (SSE) client.","archived":false,"fork":false,"pushed_at":"2019-01-24T10:51:45.000Z","size":32,"stargazers_count":238,"open_issues_count":8,"forks_count":26,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-07T20:50:04.234Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heremaps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-01T07:12:36.000Z","updated_at":"2025-02-20T00:42:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"22922ed2-ee28-49ce-b77b-de6a505c5c9a","html_url":"https://github.com/heremaps/oksse","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/heremaps/oksse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heremaps%2Foksse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heremaps%2Foksse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heremaps%2Foksse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heremaps%2Foksse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heremaps","download_url":"https://codeload.github.com/heremaps/oksse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heremaps%2Foksse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271378680,"owners_count":24749192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T20:07:34.851Z","updated_at":"2025-08-20T20:32:34.014Z","avatar_url":"https://github.com/heremaps.png","language":"Java","readme":"[![Build Status](https://travis-ci.org/heremaps/oksse.svg?branch=master)](https://travis-ci.org/heremaps/oksse)\n\n# Introduction\n\nOkSse is an extension library for OkHttp to create a Server-Sent Event (SSE) client\n\n[Server-sent events](https://www.w3.org/TR/eventsource/) is a standard describing how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a client.\n\n# Integration\n\nAdd JitPack repository:\n\n```groovy\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\nAdd OkSse dependency:\n```groovy\ndependencies {\n    implementation 'com.github.heremaps:oksse:0.9.0'\n}\n```\n\n# Usage\n\nYou can create an OkSse instance either using an already existing OkHttp client instance, or let OkSse create a default one instead.\n\nThe following code creats a request that points to our SSE server and uses the OkSse instance to create a new ServerSentEvent connection:\n\n```java\nRequest request = new Request.Builder().url(path).build();\nOkSse okSse = new OkSse();\nServerSentEvent sse = okSse.newServerSentEvent(request, listener);\n```\n\nThis implements the ServerSentEvent listener to get notified of the channel status and the received messages or comments:\n\n```java\nnew ServerSentEvent.Listener() {\n    @Override\n    public void onOpen(ServerSentEvent sse, Response response) {\n        // When the channel is opened\n    }\n\n    @Override\n    public void onMessage(ServerSentEvent sse, String id, String event, String message) {\n        // When a message is received\n    }\n\n    @WorkerThread\n    @Override\n    public void onComment(ServerSentEvent sse, String comment) {\n       // When a comment is received\n    }\n\n    @WorkerThread\n    @Override\n    public boolean onRetryTime(ServerSentEvent sse, long milliseconds) {\n        return true; // True to use the new retry time received by SSE\n    }\n\n    @WorkerThread\n    @Override\n    public boolean onRetryError(ServerSentEvent sse, Throwable throwable, Response response) {\n        return true; // True to retry, false otherwise\n    }\n\n    @WorkerThread\n    @Override\n    public void onClosed(ServerSentEvent sse) {\n        // Channel closed\n    }\n```\n\nWhen done listing from SSE, remember to close the channel and clear resources:\n\n\n```java\nsse.close();\n```\n\nOnce closed, you will need to create a new instance.\n\n## Alternative constructor\n\nYou can provide your own OkHttp client when creating a new OkSse instance.\n\n```java\nOkHttpClient client = new OkHttpClient.Builder().readTimeout(0, TimeUnit.SECONDS).build();\nOkSse oksse = new OkSse(client)\n```\nNote the read timeout set to 0, this is required in order to keep the connection alive, if not OkHttp will close the channel after timeout is reached.\n\n# License\n\nCopyright (c) 2017 HERE Europe B.V.\n\nPlease see the [LICENSE](./LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheremaps%2Foksse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheremaps%2Foksse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheremaps%2Foksse/lists"}