Exposing business functionalities as managed services or APIs has become a key requirement
of the modern enterprise architecture. However, web services/SOA is not really the ideal
solution to cater to such requirements, due to the complexity of the Web Service-related
technologies such as SOAP (used as the message format for inter-service communication), WSSecurity (to secure messaging between services), WSDLs (to define the service contract), etc.,
and the lack of features to build an ecosystem around APIs (self-servicing, etc.)
• Therefore, most organizations put a new API Management/API Gateway layer on top of the
existing SOA implementations. This layer is known as the API façade, and it exposes a simple
API for a given business functionality and hides all the internal complexities of the ESB/Web
Services layer. The API layer is also used for security, throttling, caching, and monetization.
xxxxxxxxxx
@SpringBootApplication
@EnableConfigurationProperties(UriConfiguration.class)
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder, UriConfiguration uriConfiguration) {
String httpUri = uriConfiguration.getHttpbin();
return builder.routes()
.route(p -> p
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri(httpUri))
.route(p -> p
.host("*.circuitbreaker.com")
.filters(f -> f
.circuitBreaker(config -> config
.setName("mycmd")
.setFallbackUri("forward:/fallback")))
.uri(httpUri))
.build();
}
@RequestMapping("/fallback")
public Mono<String> fallback() {
return Mono.just("fallback");
}
}
@ConfigurationProperties
class UriConfiguration {
private String httpbin = "http://httpbin.org:80";
public String getHttpbin() {
return httpbin;
}
public void setHttpbin(String httpbin) {
this.httpbin = httpbin;
}
}