https://github.com/datastaxdevs/quarkus-astra-intro-demo
https://github.com/datastaxdevs/quarkus-astra-intro-demo
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/datastaxdevs/quarkus-astra-intro-demo
- Owner: datastaxdevs
- License: mit
- Created: 2021-10-25T03:43:33.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-17T04:07:47.000Z (over 3 years ago)
- Last Synced: 2023-03-04T04:05:50.420Z (over 3 years ago)
- Language: JavaScript
- Size: 1.13 MB
- Stars: 1
- Watchers: 5
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is used in conjunction with the workshop at https://github.com/datastaxdevs/workshop-intro-quarkus-cassandra.
## Mappers vs Raw CQL
This version has a build-time property (not overridable at runtime) called `astra-service.type`. By default, if this property is undefined _OR_ has the value `cql-session`, then [`CqlSessionAstraService`](src/main/java/com/datastaxdev/todo/service/CqlSessionAstraService.java) will be injected as the implementation for [`AstraService`](src/main/java/com/datastaxdev/todo/service/AstraService.java). This version uses hand-crafted CQL queries executed against the `CqlSession`.
If, at build time, `astra-service.type=dao`, then [`MapperAstraService`](src/main/java/com/datastaxdev/todo/service/MapperAstraService.java) will be used instead. This version will use the [Cassandra Entity Modeling](https://quarkus.io/guides/cassandra#creating-the-data-model-and-data-access-objects).
The [`AstraConfig`](src/main/java/com/datastaxdev/todo/config/AstraConfig.java) class contains everything needed for reading this flag at build time and injecting the appropriate [`AstraService`](src/main/java/com/datastaxdev/todo/service/AstraService.java) implementation.
## Blocking vs Async/reactive
A mix of blocking vs reactive endpoints has been done. In [`TodoResource`](src/main/java/com/datastaxdev/todo/rest/TodoResource.java), the `getTodos` (`GET` to `/api/todo/{list_id}`) and `setTodo` (`POST` to `/api/todo/{list_id}`) methods are implemented as reactive methods. This means that their execution happens on the event loop thread, whereas all of the other methods are blocking. Quarkus will offload those executions onto worker threads (read about [Quarkus smart dispatching](https://quarkus.io/blog/resteasy-reactive-smart-dispatch) for more information).
Subsequently, the `getTodos` and `setTodo` methods in [`AstraService`](src/main/java/com/datastaxdev/todo/service/AstraService.java) have been updated to be reactive. Both the CQL and entity mapper implementations have been updated to use the [Cassandra driver's reactive support](https://quarkus.io/guides/cassandra#reactive) as well.
As you can see, blocking & reactive can co-exist in the same class!