'How to handle webhooks in the function that called them
Hi so im a new user there might not frame the question well but we all have to start somewhere:
Im interacting with a webserver where im calling for a transaction, the transaction is added to a queue and the result is sent when processing of the transaction is complete. This is done asyncronously in the server so the result that is the deatils of the transaction(successful or not are sent to an endpoint).
in summary: So i have a function that calls the server through an api requesting the transaction i recieve a response saying the transaction is being processed, and the result is sent to and endpoint.
My question: If i was doing some processing that required a successful transaction that is i required the result to be transaction successful for me to proceed how would i go about it. Basically i have to wait for the result from the server to know what the status of the transaction is then i can proceed with processing.
How i call the service on the server
WebClient client = WebClient.builder()
.baseUrl(base_url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
Response response = client.post()
.body(Mono.just(request), TibcoRequest.class)
.retrieve()
.bodyToMono(Response.class)
.block();
The response is pojo containing the status code if the server accepted the request or not
i recieve the result in the enpoint that i defined in the request something like
http\:myurl.com\endpoint\result and for that i have the controller below
@PostMapping(value = "transactions/callback", consumes = MediaType.APPLICATION_JSON_VALUE)
public void processG2Webhook(@RequestBody Request request) {
System.out.println(request);
//update core service
transactionService.updateTransactionByrequest(request);
}
How could i implement it such that i can access the result of the webhook in the initial call what do i have to read or look at in order to be able to that
Please help me thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
