In a Spring Cloud Gateway server, is it necessary to build a WebClient for sending request manually? - spring

If I want to send some request to a microservice under the gateway (for example, trigger by a timer), should I build a new WebClient, or just use an existing bean?

Related

Spring Boot Reactive WebService

We want to build a rest API to service high request volumes. I'm planning to build it using Spring Reactive(WebFlux) or using Spring Boot Async. We have multiple different clients who will be invoking our service.
Do I need to worry about different clients who will be consuming this service? Meaning if I build the API using Reactive or Async, will all the clients be able to consume this seemlessly?
Meaning if build a reactive Rest API, will the client using RestTemplate be able to consume or do they need to use WebClient only?
Yes, your (not non blocking) clients will still be able to consume a reactive service.

Spring Serverless HTTP Poller

I want to implement a serverless function that polls an HTTP endpoint and publishes the response to a messaging queue.
My initial thought is to build a spring boot application using spring integration gateway and adapters for HTTP polling and publishing to queue (and deploy as lambda). Is there a better option in the spring stack?
I looked at spring cloud function, spring cloud stream, spring cloud task. Any suggestions?
In Spring Cloud Stream this type of microservice is called source. So, you need to have a Supplier bean based on Spring Integration Java DSL to build a simple flow to let Spring Cloud Stream to poll it periodically and produce a result into bound destination.
Something like this:
#Bean
public IntegrationFlow pollingHttpFlow() {
return IntegrationFlows
.from(Supplier.class, gateway -> gateway.beanName("httpSupplier"))
.handle(Http.outboundGateway("http://somehost"))
.get();
}
See a blog post about this kind of interoperability: https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration

Using Gateway to consume Spring Boot application from Spring Integration application

I am just starting with Spring Integration with Spring Boot 2.
I am working on a application which uses Spring Integration's HTTP outbound gateway to consume a Spring boot Service.
I am consuming the spring boot service from Spring Integration application using Gateway.
When I call the Gateway method which in turn will use the outbound gateway to call the spring boot service, the request does not seem to be completed. It is just going on when I make the HTTP GET request via the browser.
The request is also not received by the Spring Boot service.
I am not able to identify what is wrong in my Integration application when using gateway to consume a Spring Boot 2 service.
I have shared my Spring Boot 2 Application and also the Integration application which I am using to consume it in the below github folder. it contains 2 folders, one for the spring Integration application and the other for the spring boot application.
https://github.com/gsamartian/spring-int-demos
I have exposed a REST interface for the Integration application using RestController.
I access the boot application from integration application via the url, http://localhost:8763/callExternalServiceViaGateway
I am able to access the spring boot application directly from its port.
If anyone can help me identify the cause it would be great.
Thanks,
Your problem that the gateway method is without any args:
#Gateway(requestChannel = "get.request.channel", replyChannel = "reply.channel")
String getCustomMessage();
In this case the gateway works as receiving. No any requests is send because nothing to wrap to the payload. See more info on the matter in the Reference Manual.
Right now I see several bugs with the payloadExpression and no arg, so I suggest you to add some String payload arg to the getCustomMessage() gateway method and perform it with an empty string.
Will take a look into the bugs and will fix them soon.
Thank you for a good sample how to catch and reproduce!
https://jira.spring.io/browse/INT-4448
https://jira.spring.io/browse/INT-4449

Spring Integration webservice outbound gateway - capturing request and response to DB with additional values

I am using Spring integration WS 2.2 outbound gateway to invoke a webservice.
One of our requirement is to capture the soap request and response xmls to the database in addition to some other values like transaction id etc.
If i use ClientInterceptor to save the request/response to DB, it only has access to the soap request and the response but not to the values like transaction Id. So is there a way to retrieve and return the soap request and response from the interceptor OR a way to pass custom values to the interceptor?
Thanks

Spring Integration - HTTP gateway and JMS

I have a requirement where client sends an HTTP requests, our application processes it and generates response and sends back the HTTP response. The request and response need to be persisted on JMS queues. In order for us to leverage Spring integration in this scenario, can we use spring integration HTTP gateways in place of our current MVC controllers ? Would I need separate gateways for each different uri mapping ? Can the HTTP gateway be integrated with JMS channels ? I would appreciate some ideas on the high level architecture using Spring Integration for this scenario.
Thanks.
The fastest on-ramp would probably to inject a Messaging Gateway (<gateway/>) into your existing controller; if you are simply archiving the request/response, you just need a simply gateway method that returns void and in the Spring Integration flow, wire the <gateway/> to a <jms:outbound-channel-adapter/>.

Resources