{"id":24617659,"url":"https://github.com/pacphi/reactive-jdbc-demo","last_synced_at":"2025-05-07T05:24:42.721Z","repository":{"id":48480911,"uuid":"138216240","full_name":"pacphi/reactive-jdbc-demo","owner":"pacphi","description":"This is a simple experiment to test Spring 5's Webflux Module's Functional Programming Model interaction with the Reactiverse reactive-pg-client.","archived":false,"fork":false,"pushed_at":"2021-07-23T13:18:57.000Z","size":87,"stargazers_count":17,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T06:51:07.192Z","etag":null,"topics":["docker","java","pcf","postgres","reactive","spring-5","spring-boot","spring-webflux"],"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/pacphi.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}},"created_at":"2018-06-21T20:03:02.000Z","updated_at":"2022-04-26T07:51:36.000Z","dependencies_parsed_at":"2022-08-24T14:39:13.374Z","dependency_job_id":null,"html_url":"https://github.com/pacphi/reactive-jdbc-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Freactive-jdbc-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Freactive-jdbc-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Freactive-jdbc-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pacphi%2Freactive-jdbc-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pacphi","download_url":"https://codeload.github.com/pacphi/reactive-jdbc-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252819595,"owners_count":21809046,"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":["docker","java","pcf","postgres","reactive","spring-5","spring-boot","spring-webflux"],"created_at":"2025-01-24T23:39:50.121Z","updated_at":"2025-05-07T05:24:42.699Z","avatar_url":"https://github.com/pacphi.png","language":"Java","readme":"# Reactive ~~JDBC~~ Experiment  \n\nThis is a simple experiment to test Spring 5's Webflux Module's [Functional Programming Model](https://docs.spring.io/spring/docs/5.0.0.BUILD-SNAPSHOT/spring-framework-reference/html/web-reactive.html#_functional_programming_model) interaction with the Reactiverse [reactive-pg-client](https://reactiverse.io/reactive-pg-client/guide/java/index.html). \n\n\u003e Disclaimer: the `reactive-pg-client` does **not** implement the [JDBC](http://download.oracle.com/otn-pub/jcp/jdbc-4_1-mrel-spec/jdbc4.1-fr-spec.pdf?AuthParam=1529679008_7acd6035892acd847bba6ff8dd5242d1) specification.\n\n## Prerequisites\n\n* An account with [Space Developer role](https://docs.cloudfoundry.org/concepts/roles.html#roles) access on a Cloud Foundry foundation, e.g., [Pivotal Web Services](https://run.pivotal.io)\n* [CF CLI](https://github.com/cloudfoundry/cli#downloads) 6.37.0 or better if you want to push the application to a Cloud Foundry (CF) instance\n* [httpie](https://httpie.org/#installation) 0.9.9 or better to simplify interaction with API endpoints\n* Java [JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) 1.8u172 or better to compile and run the code\n* [Gradle](https://gradle.org/releases/) 4.8 or better to build and package source code\n* Docker for [Mac](https://store.docker.com/editions/community/docker-ce-desktop-mac) or [Windows](https://store.docker.com/editions/community/docker-ce-desktop-windows) for spinning up a local instance of Postgres and Adminer (a database administration interface)\n\n\n## Clone\n\n```bash\ngit clone https://github.com/pacphi/reactive-jdbc-demo.git\n```\n\n## How to build\n\n```bash\ncd reactive-jdbc-demo\ngradle build\n```\n\n## How to run locally \n\n1. Prepare database\n\n    Open a Terminal session, then type\n\n    ```bash\n    docker-compose up -d\n    ```\n\n2. Login to [Adminer](https://www.adminer.org) interface \n\n    Open a browser and visit `http://localhost:9090`\n\n    Credentials are:\n\n    * System =\u003e `PostgreSQL`\n    * Server =\u003e `db`\n    * Username =\u003e `admin`\n    * Password =\u003e `passw0rd`\n    * Database =\u003e `people`\n\n    Click the `Login` button\n\n3. Click on the `SQL command` link \n\n    Link is in the upper left hand-corner of the interface\n\n4. Cut-and-paste the contents of [people.ddl](people.ddl) into the text area, then click the `Execute` button\n\n5. Start the application\n\n    Start a new Terminal session and type\n\n    ```bash\n    gradle bootRun\n    ```\n\n6. Let's create some data using the API\n\n    ```bash\n    http POST localhost:8080/person firstName=Dweezil lastName=Zappa age=48\n\n    HTTP/1.1 202 Accepted\n    content-length: 0\n    ```\n\n7. Verify that we can find the person we added\n\n    ```bash\n    http localhost:8080/person\n\n    HTTP/1.1 200 OK\n    Content-Type: application/json\n    transfer-encoding: chunked\n\n    [\n        {\n            \"age\": 48,\n            \"firstName\": \"Dweezil\",\n            \"id\": \"582279d1-9bd1-4e49-946c-ac720de0e04f\",\n            \"lastName\": \"Zappa\"\n        }\n    ]\n    ```\n\n8. Let's ask for a person by id\n\n    ```bash\n    http localhost:8080/person/582279d1-9bd1-4e49-946c-ac720de0e04f\n\n    HTTP/1.1 200 OK\n    Content-Length: 95\n    Content-Type: application/json\n\n    {\n        \"age\": 48,\n        \"firstName\": \"Dweezil\",\n        \"id\": \"582279d1-9bd1-4e49-946c-ac720de0e04f\",\n        \"lastName\": \"Zappa\"\n    }\n    ```\n\n## How to shutdown locally\n\n1. Stop the application\n\n    Visit the Terminal session where you started application and press `Ctrl+c`\n\n2. Shutdown Postgres and Adminer interface\n\n    Visit the Terminal session where you invoked `docker-compose-up -d` and type\n\n    ```bash\n    docker-compose down\n    ```\n\n    Note: the data volume is persistent!  If you want to destroy all unused volumes and reclaim some additional space, type\n\n    ```bash\n    docker volume prune\n    ```\n\n## How to run on Cloud Foundry\n\n1. Authenticate to a foundation using the API endpoint. \n    \u003e E.g., login to [Pivotal Web Services](https://run.pivotal.io)\n\n    ```bash\n    cf login -a https:// api.run.pivotal.io\n    ```\n\n2. Push the app, but don't start it\n\n    ```bash\n    cf push reactive-jdbc-demo --random-route --no-start -p ./build/libs/reactive-jdbc-demo-0.0.1-SNAPSHOT.jar -m 1G -b https://github.com/cloudfoundry/java-buildpack.git\n    ```\n\n3. Let's fire fire up a Postgres instance\n\n    \u003e We're going to use [ElephantSQL](https://www.elephantsql.com)\n\n    ```bash\n    cf cs elephantsql panda {service name}\n    ```\n\n    \u003e Note: this is going to cost you $19/month to keep alive\n    \u003e Replace {service name} above with your desired service name\n\n4. Next we'll bind the service to the application\n\n    ```bash\n    cf bs reactive-jdbc-demo {service name}\n    ```\n\n    \u003e Make sure {service name} above matches what you defined in Step 3\n\n5. Let's verify that `VCAP_SERVICES` was properly injected\n\n    ```bash\n    cf env reactive-jdbc-demo\n \n    Getting env variables for app reactive-jdbc-demo in org scooby-doo / space dev as dweezil@zappa.com...\n    OK\n\n    System-Provided:\n    {\n    \"VCAP_SERVICES\": {\n    \"elephantsql\": [\n    {\n        \"binding_name\": null,\n        \"credentials\": {\n        \"max_conns\": \"20\",\n        \"uri\": \"postgres://blxrphig:XXX0bLLyWpiUqKozCRhzygyhnpOMlMC@elmer-01.db.elephantsql.com:5432/banzlhig\"\n        },\n        ...\n    ```\n\n    \u003e We're interested in `vcap_services.elephantsql.uri`\n    \u003e The URI consists of {vendor}://{username}:{password}@{server}:5432/{database}\n\n6. We'll set an environment variable\n\n    ```bash\n    cf set-env reactive-jdbc-demo PG_LOOKUP_KEY {service name}\n    ```\n    \u003e `{service name}` above should match value in steps 3 and 4\n\n7. Now let's startup the application\n\n    ```bash\n    cf start reactive-jdbc-demo\n    ```\n\n8. Launch Adminer to administer the database\n\n    The `people` table doesn't exist yet, so we need to create it\n\n    ```bash\n    docker-compose up -d\n    ```\n\n    Open a browser and visit `http://localhost:9090`\n\n    Credentials are:\n\n    * System =\u003e `PostgreSQL`\n    * Server =\u003e `{server}`\n    * Username =\u003e `{username}`\n    * Password =\u003e `{password}`\n    * Database =\u003e `{database}`\n\n    Replace all bracketed values above with what you learned from Step 5\n\n    Click the `Login` button\n\n9. Click on the `SQL command` link \n\n10. Cut-and-paste the contents of [people.ddl](people.ddl) into the text area, then click the `Execute` button\n\n11. Follow steps 6-8 above in `How to run locally` to interact with API\n\n    But replace occurrences of `localhost:8080` with URL to application hosted on Cloud Foundry\n\n*Congratulations! You've just pushed and interacted with a 100% reactive and cloud native app.*\n\n## How to spin down workloads on Cloud Foundry\n\n1. Stop the application\n\n    ```bash\n    cf stop reactive-jdbc-demo\n    ```\n\n2. Unbind the database instance\n\n    ```bash\n    cf us reactive-jdbc-demo {service name}\n    ```\n    \u003e `{service name}` above should match value in `How to run on Cloud Foundry` steps 3 and 4\n\n3. Delete the database instance\n\n    ```bash\n    cf ds {service name}\n    ```\n    \u003e `{service name}` above should match value in `How to run on Cloud Foundry` steps 3 and 4\n\n4. Delete the application\n\n    ```bash\n    cf delete reactive-jdbc-demo\n    ```\n    \n## What to look forward to?\n\n* Asynchronous Database Access ([ADBA](https://blogs.oracle.com/java/jdbc-next:-a-new-asynchronous-api-for-connecting-to-a-database))\n* ADBA over JDBC ([AoJ](https://github.com/oracle/oracle-db-examples/blob/master/java/AoJ/README.md))\n\nOracle continues to work on ADBA while having released AoJ under an Apache license to get community feedback. \n\nMaybe we will see something concrete in JDK 11? \n\n## What else is there to play with?\n\n* [rxjava2-jdbc](https://github.com/davidmoten/rxjava2-jdbc)\n* [Vert.x JDBC Client](https://vertx.io/docs/vertx-jdbc-client/java/)\n* Reactive Relational Database Connectivity Client ([R2DBC](https://github.com/r2dbc/r2dbc-client))\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacphi%2Freactive-jdbc-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacphi%2Freactive-jdbc-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacphi%2Freactive-jdbc-demo/lists"}