{"id":47755911,"url":"https://github.com/macielti/service","last_synced_at":"2026-05-02T01:01:08.447Z","repository":{"id":261887871,"uuid":"885622026","full_name":"macielti/service","owner":"macielti","description":"Service Component is a Pedestal service Integrant component","archived":false,"fork":false,"pushed_at":"2026-05-01T03:30:28.000Z","size":96,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-01T03:41:48.614Z","etag":null,"topics":["clojure","integrant","pedestal"],"latest_commit_sha":null,"homepage":"https://github.com/macielti/service-component","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/macielti.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-09T00:47:29.000Z","updated_at":"2026-05-01T03:30:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"5be27be1-d9de-4e22-bf5f-9c7e4334350a","html_url":"https://github.com/macielti/service","commit_stats":null,"previous_names":["macielti/service-component","macielti/service"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/macielti/service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macielti%2Fservice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macielti%2Fservice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macielti%2Fservice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macielti%2Fservice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macielti","download_url":"https://codeload.github.com/macielti/service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macielti%2Fservice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32518744,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["clojure","integrant","pedestal"],"created_at":"2026-04-03T04:20:42.743Z","updated_at":"2026-05-02T01:01:08.401Z","avatar_url":"https://github.com/macielti.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Clojars Project](https://img.shields.io/clojars/v/net.clojars.macielti/service-component.svg)](https://clojars.org/net.clojars.macielti/service-component)\n![Compatible with GraalVM](https://img.shields.io/badge/compatible_with-GraalVM-green)\n\n# Service\n\nService is a Pedestal service Integrant component.\n\nIf you will be using this library in a project intended to be compiled using GraalVM, you should add the following\ndependencies to your project:\n\n``` clojure\n  [net.clojars.macielti/service \"x.y.z\"]\n  [io.pedestal/pedestal.service \"0.8.1\"]\n  [io.pedestal/pedestal.jetty \"0.8.1\"]\n  [io.pedestal/pedestal.error \"0.8.1\"]\n```\n\n## Configuration\n\nThe service component accepts configuration through the `:service` key in your config map. The following options are available:\n\n| Key                    | Type                | Required | Default           | Description                                                                                                    |\n|------------------------|---------------------|----------|-------------------|----------------------------------------------------------------------------------------------------------------|\n| `:host`                | String              | Yes      | —                 | The host address to bind the server to (e.g., `\"0.0.0.0\"`).                                                   |\n| `:port`                | Integer             | Yes      | —                 | The port number to listen on (e.g., `8080`).                                                                   |\n| `:idle-timeout-ms`     | Integer             | No       | `30000`           | Jetty idle timeout in milliseconds. Connections idle beyond this duration are closed.                          |\n| `:min-threads`         | Integer             | No       | `8`               | Minimum number of threads kept alive in the Jetty thread pool.                                                 |\n| `:max-threads`         | Integer             | No       | `50`              | Maximum number of concurrent threads. Acts as a concurrency cap for both platform and virtual thread modes.    |\n| `:max-queue-size`      | Integer             | No       | `200`             | Maximum number of requests that can queue while all threads are busy (platform threads only). Requests beyond this limit are rejected with HTTP 503. |\n| `:use-virtual-threads` | Boolean             | No       | `true`            | When `true` and running on Java 21+, uses Jetty's `VirtualThreadPool` instead of `QueuedThreadPool`. Falls back to platform threads automatically on Java \u003c 21. |\n\n### Thread pool behaviour\n\nThe component selects the thread pool implementation at startup based on `:use-virtual-threads` and the detected JVM version:\n\n**Virtual threads (Java 21+, default)**\n\nUses Jetty's `VirtualThreadPool`. Each request runs in its own virtual thread, which is cheap to create (~few KB) and automatically yields during blocking I/O, allowing thousands of concurrent requests without stacking platform threads. Concurrency is bounded by `:max-threads` via a semaphore. `:min-threads` and `:max-queue-size` are ignored in this mode.\n\n**Platform threads (Java \u003c 21, or `:use-virtual-threads false`)**\n\nUses Jetty's `QueuedThreadPool` backed by a `BlockingArrayQueue` of size `:max-queue-size`. Requests are served by a pool of `:min-threads` to `:max-threads` platform threads. When all threads are busy and the queue is full, new requests are rejected immediately with **HTTP 503**, providing explicit backpressure instead of silently growing memory until OOM.\n\n### Example\n\n```clojure\n{:service {:host                \"0.0.0.0\"\n           :port                8080\n           :idle-timeout-ms     60000\n           :min-threads         8\n           :max-threads         200\n           :max-queue-size      500\n           :use-virtual-threads true}}\n```\n\n### Recommended values by workload\n\n| Scenario                    | `:min-threads` | `:max-threads` | `:max-queue-size` |\n|-----------------------------|----------------|----------------|-------------------|\n| IO-bound (DB, HTTP calls)   | `8`            | `100`–`200`    | `500`             |\n| CPU-bound                   | `4`            | `nCPU × 2`    | `50`              |\n| Small pods / low memory     | `4`            | `20`           | `100`             |\n| Java 21+ (virtual threads)  | —              | `500`+         | —                 |\n\n\u003e **Note:** If `:idle-timeout-ms` is not provided, a default of **30 seconds** (`30000` ms) is applied to prevent stalled connections from tying up server resources.\n\n## Interceptors\n\nCORS and other default request interceptors must be configured **in your consuming application**, not at the component level.\n\nThe service component provides two built-in interceptors:\n- `error-handler-interceptor` — handles exception-to-response conversion.\n- `components-interceptor` — injects the Integrant components map into the request context.\n\nTo add CORS, authentication, rate limiting, or other cross-cutting concerns, use one of these approaches in your application:\n\n**Option 1: Per-route interceptors**\n\nDefine interceptors on individual routes in your route definitions:\n```clojure\n[\"/api/resource\"\n {:get {:handler my-handler\n        :interceptors [cors-interceptor auth-interceptor]}}]\n```\n\n**Option 2: Connector-level default interceptors**\n\nUse `io.pedestal.connector/with-default-interceptors` in your route setup to apply interceptors to all routes:\n```clojure\n(io.pedestal.connector/with-default-interceptors connector :allowed-origins cors-origins)\n```\n\n## License\n\nCopyright © 2024 Bruno do Nascimento Maciel\n\nThis program and the accompanying materials are made available under the\nterms of the Eclipse Public License 2.0 which is available at\nhttp://www.eclipse.org/legal/epl-2.0.\n\nThis Source Code may also be made available under the following Secondary\nLicenses when the conditions for such availability set forth in the Eclipse\nPublic License, v. 2.0 are satisfied: GNU General Public License as published by\nthe Free Software Foundation, either version 2 of the License, or (at your\noption) any later version, with the GNU Classpath Exception which is available\nat https://www.gnu.org/software/classpath/license.html.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacielti%2Fservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacielti%2Fservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacielti%2Fservice/lists"}