
driven-adapter.consumer-rest.reactive-rest-consumer.rest-consumer.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaffold-clean-architecture Show documentation
Show all versions of scaffold-clean-architecture Show documentation
Gradle plugin to create a clean application in Java that already works, It follows our best practices!
package {{package}}.consumer;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
@Service
{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
public class RestConsumer /* implements Gateway from domain */{
private final WebClient client;
{{^lombok}}
public RestConsumer(WebClient client) {
this.client = client;
}
{{/lombok}}
// these methods are an example that illustrates the implementation of WebClient.
// You should use the methods that you implement from the Gateway from the domain.
@CircuitBreaker(name = "testGet" /*, fallbackMethod = "testGetOk"*/)
public Mono testGet() {
return client
.get()
.retrieve()
.bodyToMono(ObjectResponse.class);
}
// Possible fallback method
// public Mono testGetOk(Exception ignored) {
// return client
// .get() // TODO: change for another endpoint or destination
// .retrieve()
// .bodyToMono(String.class);
// }
@CircuitBreaker(name = "testPost")
public Mono testPost() {
{{#lombok}}
ObjectRequest request = ObjectRequest.builder()
.val1("exampleval1")
.val2("exampleval2")
.build();
{{/lombok}}
{{^lombok}}
ObjectRequest request = new ObjectRequest();
request.setVal1("exampleval1");
request.setVal2("exampleval2");
{{/lombok}}
return client
.post()
.body(Mono.just(request), ObjectRequest.class)
.retrieve()
.bodyToMono(ObjectResponse.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy