https://github.com/auritylab/spring-gcp-tasks
GCP Cloud Tasks in Spring
https://github.com/auritylab/spring-gcp-tasks
cloud-tasks experimental kotlin spring-boot
Last synced: 16 days ago
JSON representation
GCP Cloud Tasks in Spring
- Host: GitHub
- URL: https://github.com/auritylab/spring-gcp-tasks
- Owner: AurityLab
- License: apache-2.0
- Created: 2019-06-19T19:33:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-22T17:31:45.000Z (almost 4 years ago)
- Last Synced: 2025-06-17T22:07:08.461Z (16 days ago)
- Topics: cloud-tasks, experimental, kotlin, spring-boot
- Language: Kotlin
- Homepage:
- Size: 749 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring GCP Cloud Tasks library
Spring-gcp-tasks is a small **experimental** library to integrate GCP Cloud Tasks into Spring projects.
Note: *This isn't production tested, but the library is in a finished state.*
---
* [Installation](https://github.com/AurityLab/spring-gcp-tasks#installation)
* [Compatibility](https://github.com/AurityLab/spring-gcp-tasks#compatibility)
* [Properties](https://github.com/AurityLab/spring-gcp-tasks#properties)
* [Usage](https://github.com/AurityLab/spring-gcp-tasks#usage)
* [Example](https://github.com/AurityLab/spring-gcp-tasks#example)---
### Installation
Repository: `https://maven.pkg.github.com/AurityLab/spring-gcp-tasks`
Gradle:
```groovy
dependencies {
implementation "com.auritylab:spring-gcp-tasks:0.1.19"
}
```Maven:
```xmlcom.auritylab
spring-gcp-tasks
0.1.19```
### Compatibility
This library is compatible with spring cloud `Hoxton` or higher (at least `Hoxton.M2`).
For everything below `Hoxton.M2` (`Greenwich` etc.) you **have** to use google-cloud-bom version `0.99.0-alpha` or higher:
Gradle:
```groovy
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}") {
bomProperty "google-cloud-bom.version", "0.99.0-alpha"
}
}
}
```Maven:
```xmlcom.google.cloud
google-cloud-bom
0.99.0-alpha
pom
import
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
```
Replace `${springCloudVersion}` with your version (e.g. `Greenwich.SR2`).
### Properties
Prefix for all properties: `com.auritylab.spring.gcp.tasks`
Property | Default | Required | Type | Description
------------ | ------------- | ------------- | ------------- | -------------
`signature-secret` | **nothing** | **yes** | `String` | Used for signing tasks before submitting to Cloud Tasks.
`default-project-id` | `null` | **no** | `String?` | Used when nothing specified in `@CloudTask` annotation.
`default-location-id` | `null` | **no** | `String?` | Used when nothing specified in `@CloudTask` annotation.
`default-queue-id` | `null` | **no** | `String?` | Used when nothing specified in `@CloudTask` annotation.
`default-worker-endpoint` | `null` | **no** | `String?` | Used when nothing specified in `@CloudTask` annotation.
`default-worker-endpoint-route` | `"/taskhandler"` | **default** | `String` | Used when nothing specified in `@CloudTask` annotation.
`default-worker-route` | `""` | **default** | `String` | Used when nothing specified in `@CloudTask` annotation.
`skip-cloud-tasks` | `false` | **default** | `Boolean` | Task submissions will be sent to the task's worker endpoint directly skipping Cloud Tasks.
`skip-task-endpoint` | `false` | **default** | `Boolean` | Task will be executed directly without networking (task's execute method blocks until task finished).
`queue-id-global-prefix` | `""` | **default** | `String` | Prefix used for all queue ids. Useful for testing or staging.Note on types:
`String` -> non-nullable
`String?` -> nullableAlso note that `default-worker-endpoint-route` and `default-worker-route` are two different properties.
The former is used for the actual route to send the task to (in combination with `default-worker-endpoint`).
The latter is a *virtual* route to map the task to the right worker.### Usage
There are two annotations for auto configuration:
`@EnableCloudTasks` and `@EnableCloudTasksWithEndpoint`The former enables spring-gcp-tasks functionality, but disables the worker endpoint.
The latter also enables the worker endpoint via a rest controller mapped to the route specified
in `com.auritylab.spring.gcp.tasks.default-worker-endpoint-route`. A configured web server is needed for this.```kotlin
@SpringBootApplication
// or @EnableCloudTasks to disable worker endpoint
@EnableCloudTasksWithEndpoint
class Applicationfun main(args: Array) {
runApplication(*args)
}
```### Example
Writing a task worker:
```kotlin
@CloudTask(route = "/notification")
class NotificationWorker : TaskWorker(Payload::class) {
override fun run(payload: Payload, id: UUID) {
println("New notification task: $payload")
}data class Payload(val str: String)
}
```Executing a task with worker above:
```kotlin
class NotificationTest(
private val notificationWorker: NotificationWorker
) {
fun execute() {
notificationWorker.execute(
NotificationWorker.Payload("test")
)
}
}
```