This project provides a simple approach to set up webhook client and webhook server functionality within a Spring Boot application. The main purpose is to enable a service (the client) to register callbacks with a remote server, perform health checks, and receive events via configured callback URLs.
The project is split into two parts:
-
Webhook Client
- Handles registration of the client to the server
- Subscribes to callbacks from the server
- Implements periodic health checks
-
Webhook Server
- Maintains a list of client callbacks
- Provides an endpoint for clients to register
- Performs health checks to ensure client callbacks are valid
- Sends events back to client callbacks
- Annotate your Application with @WebHookClient
- Create a bean of WebHookClientService with the specified type that should be processed.
@Bean
fun webHookClientService(objectMapper: ObjectMapper): WebhookClientService<Test> {
return WebhookClientService(Test::class.java, this::test, objectMapper)
}
fun test(test: Test) {
// handle test
}
}
- Annotate your Application with @WebHookServer
- Dependency Inject WebHookServerService and call callback
fun test() {
webHookServerService.callback(Testt("OK", "BINGO"))
}