{"id":21939362,"url":"https://github.com/r2dbc/r2dbc-pool","last_synced_at":"2025-05-14T17:10:00.194Z","repository":{"id":37723351,"uuid":"178276394","full_name":"r2dbc/r2dbc-pool","owner":"r2dbc","description":"Connection Pooling for Reactive Relational Database Connectivity","archived":false,"fork":false,"pushed_at":"2024-11-28T15:19:10.000Z","size":552,"stargazers_count":347,"open_issues_count":31,"forks_count":55,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-04-13T10:53:51.047Z","etag":null,"topics":["connection-pool","database","r2dbc","reactive"],"latest_commit_sha":null,"homepage":"https://r2dbc.io","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/r2dbc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","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":"2019-03-28T20:21:50.000Z","updated_at":"2025-02-27T00:32:51.000Z","dependencies_parsed_at":"2024-06-21T19:08:52.145Z","dependency_job_id":"0207de66-ae29-4d23-8006-c35b8e54ab2c","html_url":"https://github.com/r2dbc/r2dbc-pool","commit_stats":{"total_commits":188,"total_committers":18,"mean_commits":"10.444444444444445","dds":"0.21808510638297873","last_synced_commit":"55f8f30be2341c09a6e05ea50cbd80d7821528b6"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r2dbc%2Fr2dbc-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r2dbc%2Fr2dbc-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r2dbc%2Fr2dbc-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r2dbc%2Fr2dbc-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r2dbc","download_url":"https://codeload.github.com/r2dbc/r2dbc-pool/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190395,"owners_count":22029632,"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","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":["connection-pool","database","r2dbc","reactive"],"created_at":"2024-11-29T02:19:09.361Z","updated_at":"2025-05-14T17:10:00.159Z","avatar_url":"https://github.com/r2dbc.png","language":"Java","funding_links":[],"categories":["数据库开发"],"sub_categories":[],"readme":"# Reactive Relational Database Connectivity Connection Pool Implementation [![Java CI with Maven](https://github.com/r2dbc/r2dbc-pool/workflows/Java%20CI%20with%20Maven/badge.svg?branch=main)](https://github.com/r2dbc/r2dbc-pool/actions?query=workflow%3A%22Java+CI+with+Maven%22+branch%3Amain) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.r2dbc/r2dbc-pool/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.r2dbc/r2dbc-pool)\n\nThis project contains a [R2DBC][r] connection pool using `reactor-pool` for reactive connection pooling.\n\n[r]: https://github.com/r2dbc/r2dbc-spi\n\n## Code of Conduct\n\nThis project is governed by the [R2DBC Code of Conduct](https://github.com/r2dbc/.github/blob/main/CODE_OF_CONDUCT.adoc). By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to [info@r2dbc.io](mailto:info@r2dbc.io).\n\n## Getting Started\n\nConfiguration of the `ConnectionPool` can be accomplished in several ways:\n\n**URL Connection Factory Discovery**\n\n```java\n// Creates a ConnectionPool wrapping an underlying ConnectionFactory \nConnectionFactory pooledConnectionFactory = ConnectionFactories.get(\"r2dbc:pool:\u003cmy-driver\u003e://\u003chost\u003e:\u003cport\u003e/\u003cdatabase\u003e[?maxIdleTime=PT60S[\u0026…]\");\n\n// Make sure to close the connection after usage.\nPublisher\u003c? extends Connection\u003e connectionPublisher = pooledConnectionFactory.create();\n```\n\n**Programmatic Connection Factory Discovery**\n\n```java\n// Creates a ConnectionPool wrapping an underlying ConnectionFactory\nConnectionFactory pooledConnectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()\n        .option(DRIVER,\"pool\")\n        .option(PROTOCOL,\"postgresql\") // driver identifier, PROTOCOL is delegated as DRIVER by the pool.\n        .option(HOST,\"…\")\n        .option(PORT,\"…\")\n        .option(USER,\"…\")\n        .option(PASSWORD,\"…\")\n        .option(DATABASE,\"…\")\n        .build());\n```\n\nThe delegated `DRIVER` (via `PROTOCOL`) above refers to the r2dbc-driver, such as `h2`, `postgresql`, `mssql`, `mysql`, `spanner`.\n\n```java\n\n// Make sure to close the connection after usage.\nPublisher\u003c? extends Connection\u003e connectionPublisher = pooledConnectionFactory.create();\n\n// Creating a Mono using Project Reactor. Using `usingWhen` for resource management and disposal.\nMono\u003cObject\u003e resultMono = Mono.usingWhen(pooledConnectionFactory.create(),\n        connection -\u003e …,\n        Connection::close);\n```\n\n**Supported ConnectionFactory Discovery Options**\n\n| Option                       | Description\n|------------------------------| -----------\n| `driver`                     | Must be `pool`\n| `protocol`                   | Driver identifier. The value is propagated by the pool to the `driver` property.\n| `acquireRetry`               | Number of retries if the first connection acquisition attempt fails. Defaults to `1`.\n| `backgroundEvictionInterval` | Interval for background eviction enabling background eviction. Disabled by default. Setting the value to `Duration.ZERO` disables background eviction even if `maxIdleTime` is configured.\n| `initialSize`                | Initial pool size. Defaults to `10`.\n| `minIdle`                    | Minimum idle connection count. Defaults to `0`.\n| `maxSize`                    | Maximum pool size. Defaults to `10`.\n| `maxLifeTime`                | Maximum lifetime of the connection in the pool. Negative values indicate no timeout. Defaults to no timeout.\n| `maxIdleTime`                | Maximum idle time of the connection in the pool. Negative values indicate no timeout. Defaults to `30` minutes.\u003cbr /\u003eThis value is used as an interval for background eviction of idle connections unless configuring `backgroundEvictionInterval`.\n| `maxAcquireTime`             | Maximum time to acquire connection from pool. Negative values indicate no timeout. Defaults to no timeout.\n| `maxCreateConnectionTime`    | Maximum time to create a new connection. Negative values indicate no timeout. Defaults to no timeout.\n| `maxValidationTime`          | Maximum time to validate connection from pool. Negative values indicate no timeout. Defaults to no timeout.\n| `poolName`                   | Name of the Connection Pool.\n| `postAllocate`               | Lifecycle function to prepare a connection after allocating it.\n| `preRelease `                | Lifecycle function to prepare/cleanup a connection before releasing it.\n| `registerJmx`                | Whether to register the pool to JMX.\n| `validationDepth`            | Validation depth used to validate an R2DBC connection. Defaults to `LOCAL`.\n| `validationQuery`            | Query that will be executed just before a connection is given to you from the pool to validate that the connection to the database is still alive.\n\nAll other properties are driver-specific.\n\n**Programmatic Configuration**\n\n```java\n// Creates a ConnectionFactory for the specified DRIVER\nConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()\n        .option(DRIVER,\"postgresql\")\n        .option(HOST,\"…\")\n        .option(PORT,\"…\")\n        .option(USER,\"…\")\n        .option(PASSWORD,\"…\")\n        .option(DATABASE,\"…\")\n        .build());\n\n// Create a ConnectionPool for connectionFactory\nConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory)\n        .maxIdleTime(Duration.ofMillis(1000))\n        .maxSize(20)\n        .build();\n\nConnectionPool pool = new ConnectionPool(configuration);\n\n\nUsing `usingWhen` for resource management and disposal.\nMono\u003cObject\u003e resultMono = Mono.usingWhen(pooledConnectionFactory.create(), // allocates a connection from the pool\n        connection -\u003e …,    // you get hold of the connection to run queries, manage transactions, …\n        Connection::close); // releases the connection back to the pool\n\n// application shutdown\npool.dispose();\n```\n\n## `Lifecycle` support\n\nThe R2DBC specification defines as of version 0.9 lifecycle support for connections (`Lifecycle.postAllocate`, `Lifecycle.preRelease`). R2DBC Pool integrates with connections that implement lifecycle methods by inspecting the actual connection. `postAllocate` is called after allocating a connection and before returning it to the caller. `preRelease` is called upon `Connection.close()`, right before returning the connection into the pool. Any error signals in `postAllocate` are propagated to the allocation subscriber. Error signals of `preRelease` are logged and suppressed. In both cases, error signals lead to immediate invalidation of the connection.\n\nAdditionally, the pool accepts custom `postAllocate` and `preRelease` functions through the builder to prepare the connection or to cleanup the connection before returning it into the pool. Custom lifecycle methods are called within the `Lifecycle` closure to ensure the connection-side lifecycle.\n\n```java\nConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory)\n    .postAllocate(connection -\u003e Flux.from(connection.createStatement(\"SET schema = …\").execute()).flatMap(Result::getRowsUpdated).then())\n    .preRelease(Connection::rollbackTransaction)\n    .build();\n\nConnectionPool pool = new ConnectionPool(configuration);\n```\n\n### Maven configuration\n\nArtifacts can be found on [Maven Central](https://search.maven.org/search?q=r2dbc-pool):\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.r2dbc\u003c/groupId\u003e\n  \u003cartifactId\u003er2dbc-pool\u003c/artifactId\u003e\n  \u003cversion\u003e${version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nIf you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.r2dbc\u003c/groupId\u003e\n  \u003cartifactId\u003er2dbc-pool\u003c/artifactId\u003e\n  \u003cversion\u003e${version}.BUILD-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003crepository\u003e\n  \u003cid\u003esonatype-nexus-snapshots\u003c/id\u003e\n  \u003cname\u003eSonatype OSS Snapshot Repository\u003c/name\u003e\n  \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n\u003c/repository\u003e\n```\n\n## Getting Help\n\nHaving trouble with R2DBC? We'd love to help!\n\n* Check the [spec documentation](https://r2dbc.io/spec/1.0.0.RELEASE/spec/html/), and [Javadoc](https://r2dbc.io/spec/1.0.0.RELEASE/api/).\n* If you are upgrading, check out the [changelog](https://r2dbc.io/spec/1.0.0.RELEASE/CHANGELOG.txt) for \"new and noteworthy\" features.\n* Ask a question - we monitor [stackoverflow.com](https://stackoverflow.com) for questions\n  tagged with [`r2dbc`](https://stackoverflow.com/tags/r2dbc). \n  You can also chat with the community on [Gitter](https://gitter.im/r2dbc/r2dbc).\n* Report bugs with R2DBC Pool at [github.com/r2dbc/r2dbc-pool/issues](https://github.com/r2dbc/r2dbc-pool/issues).\n\n## Reporting Issues\n\nR2DBC uses GitHub as issue tracking system to record bugs and feature requests. \nIf you want to raise an issue, please follow the recommendations below:\n\n* Before you log a bug, please search the [issue tracker](https://github.com/r2dbc/r2dbc-pool/issues) to see if someone has already reported the problem.\n* If the issue doesn't already exist, [create a new issue](https://github.com/r2dbc/r2dbc-pool/issues/new).\n* Please provide as much information as possible with the issue report, we like to know the version of R2DBC Pool that you are using and JVM version.\n* If you need to paste code, or include a stack trace use Markdown ``` escapes before and after your text.\n* If possible try to create a test-case or project that replicates the issue. \nAttach a link to your code or a compressed file containing your code.\n\n## Building from Source\n\nYou don't need to build from source to use R2DBC Pool (binaries in Maven Central), but if you want to try out the latest and greatest, R2DBC Pool can be easily built with the\n[maven wrapper](https://github.com/takari/maven-wrapper). You also need JDK 1.8.\n\n```bash\n $ ./mvnw clean install\n```\n\nIf you want to build with the regular `mvn` command, you will need [Maven v3.5.0 or above](https://maven.apache.org/run-maven/index.html).\n\n_Also see [CONTRIBUTING.adoc](https://github.com/r2dbc/.github/blob/main/CONTRIBUTING.adoc) if you wish to submit pull requests. Commits require `Signed-off-by` (`git commit -s`) to ensure [Developer Certificate of Origin](https://developercertificate.org/)._\n\n## Staging to Maven Central\n\nTo stage a release to Maven Central, you need to create a release tag (release version) that contains the desired state and version numbers (`mvn versions:set versions:commit -q -o -DgenerateBackupPoms=false -DnewVersion=x.y.z.(RELEASE|Mnnn|RCnnn`) and force-push it to the `release-0.x` branch. This push will trigger a Maven staging build (see `build-and-deploy-to-maven-central.sh`).\n\n## License\nThis project is released under version 2.0 of the [Apache License][l].\n\n[l]: https://www.apache.org/licenses/LICENSE-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr2dbc%2Fr2dbc-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr2dbc%2Fr2dbc-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr2dbc%2Fr2dbc-pool/lists"}