Communication between Microservices: Spring cloud OpenFeign vs WebClient/RestTemplate - spring-cloud

Any idea please about the best way to use for back to back communication ?
spring cloud OpenFeign or WebClient/RestTemplate ?
I think Feign client should be used when spring cloud gateway need to
communicate to other microservices, whereas WebClient/RestTemplate should be used for back to back communication.
Am I wrong ?

WebClient (RestTemplate - deprecated to support WebClient)
Supports reactive call
underlying HTTP client libraries such as Reactor Netty
Part of spring framework - WebFlux || Doc will give you more
Comes in 2 flavour - Annotation and functional way
Personally I found it very useful while working with OAuth2 creating bean webClient, before making call it needs to be authenticated with token, ServerOAuth2AuthorizedClientExchangeFilterFunction will ease each call with just one time configuration
OpenFeign
Reactive - need to use 3rd party - com.playtika.reactivefeign
Fits best if you want call in blocking way
Part of Spring cloud
Netflix fully transferred Feign to the open-source community under a new project named OpenFeign

Related

correlationId propagated to spring sleuth 1.x

I have the following setup:
Proxy (P) -- HTTP --> Spring Boot 2 app (X) -- HTTP --> Spring Boot 1 app (Y)
The proxy sends the requestId as an HTTP header which I need to include in the logs of both X and Y.
For the X app I could easily do it with the support of Spring Cloud Sleuth 2 using
spring:
sleuth:
propagation-keys: requestId
and creating a CurrentTraceContext implementation with inspiration from Slf4jCurrentTraceContext where I add
MDC.put("requestId", ExtraFieldPropagation.get(currentSpan, "requestId"));
and then I can easily add it to the logs using the following log pattern:
%d{yy-MM-dd E HH:mm:ss.SSS} %5p [component=${springAppName},requestId=%X{requestId:-}] %m%n"
But now I need to propagate the requestId also to Y app.
Unfortunately there I cannot leverage the goodies introduced in Spring Cloud Sleuth 2.0, (like TraceContext from brave library) since that is a Spring Boot 1.x app.
Wondering what are the options?
I was thinking to extend the Slf4jSpanLogger and inject into DefaultTracer but not sure how to get the requestId there is no TraceContext in SpanLogger.
requestId has to be there in the headers. You would have to modify the current logic of parsing the HTTP headers for Boot 1.x and retrieve that value from the headers and put it in the span.
The easiest way however would be to propagate that value as baggage cause baggage works out of the box for Boot 1.x. That way if we see the baggage- prefixed headers, Sleuth 1.3.x will automatically propagate it. Remember to whitelist the baggage in Boot 2.0.

Marklogic : JAVA API - Dynamic Database and REST Server

I am trying to see whether MarkLogic Java API can be used to create a content database and REST Server?
I went through te Java API but I dont see any reference.
Is it possible to create a REST Server through MarkLogic Java API?
I appreciate any links or pointers regarding this.
No, that's beyond the scope of the Java Client API. The Java Client API must connect to a REST Server after it's already created. You can, however, use the /rest-apis service on port 8002 via your favorite generic REST client API for Java. To see an example of how to do this with Apache HttpClient, see Bootstrapper.java. You can use it directly like the unit tests setup util TestServerBootstrapper.java does with this code:
Bootstrapper.main(new String[] {
"-configuser", username,
"-configpassword", password,
"-confighost", host,
"-restserver", "java-unittest",
"-restport", ""+port,
"-restdb", "java-unittest"});

Spring Cloud Stream Rabbit Binder Routing Key always '#'

Version: Spring Boot: 1.4.2.RELEASE
Spring Cloud Deps: Brixton.SR7
Here is my application.properties of a processor app.
logging.level.=DEBUG
server.port=0
logging.file=traveller-events-processor.log
server.port=0
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey='aa'
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey=aa
spring.cloud.stream.rabbit.bindings.input.consumer.bindQueue=true
spring.cloud.stream.rabbit.bindings.input.consumer.routing-key='aa'
spring.cloud.stream.rabbit.bindings.input.consumer.routingKey='aa'
spring.cloud.stream.bindings.input.destination=events-exchange
spring.cloud.stream.bindings.input.group=eventconsumersgroup
spring.cloud.stream.bindings.output.destination=work.out
spring.cloud.stream.bindings.output.contentType=text/plain
spring.cloud.stream.bindings.output.binder=rabbit
spring.cloud.stream.bindings.output.group=traveller-events-output-group
When I start this app, events-exchange is created as expected and bound to a queue named: events-exchange.eventconsumersgroup (which is also ok). But the routingKey is always '#'. I've tried with all the options I have fished from various documentations. Am I missing something here?
I want this app to only subscribe to certain messages (which I want to achieve via the routing key).
I see that Brixton.SR7 uses 1.0.2.RELEASE of Spring Cloud Stream and I don't seem to find the routingKey as a Rabbit consumer property. Do you want to upgrade to Spring Cloud Camden release or the latest one so that you can try using the consumer property: bindingRoutingKey as mentioned here

Does Feign retry require some sort of configuration?

I just tried to do a attempted a seamless upgrade of a service in a test setup. The service is being accessed by a Feign client. And naively I was under the impression that with multiple instances available of the service, the client would retry another instance if it failed to connect to one.
That, however, did not happen. But I cannot find any mention of how Feign in Spring Cloud is supposed to be configured to do this? Although I have seen mentions of it supporting it (as opposed to using RestTemplate where you would use something like Spring Retry?)
If you are using ribbon you can set properties similar to the following (substituting "localapp" for your serviceid):
localapp.ribbon.MaxAutoRetries=5
localapp.ribbon.MaxAutoRetriesNextServer=5
localapp.ribbon.OkToRetryOnAllOperations=true
ps underneath Feign has a Retryer interface, which was made to support things like Ribbon.
https://github.com/Netflix/feign/blob/master/core/src/main/java/feign/Retryer.java
see if property works - OkToRetryOnAllOperations: true
You can refer application ->
https://github.com/spencergibb/spring-cloud-sandbox/blob/master/spring-cloud-sandbox-sample-frontend/src/main/resources/application.yml
Spencer was quick...was late by few minutes :-)

Can ASP.NET Web API methods be called from a Windows CE app / CF 3.5?

We were thinking about doing something like WCF / REST - I think the techn[ique,ology] was called ADO.NET Data Services in VS 2008 / .NET 3.5 - anyway, something like a RESTful receiving and transmitting of data from a CF 3.5 app and a desktop .NET 4 app to simplify the client / Windows CE app so that it simply sends and receives XML or JSON data, rather than connecting to a remote database or so.
However, according to Where to start REST web service in C# or ASP.Net:
"REST in WCF no longer supported - now it points to ASP"
From the same link:
"ASP.NET Web API is now the Microsoft framework for creating RESTful services.
http://www.asp.net/web-api"
Okay, I think we can do that (WebAPI) - the plan is to host the server/service in IIS; however: Can ASP.NET Web API methods be called from CF 3.5? Does anybody have examples of such?
As long as CF 3.5 can make http requests, then you should be able to make rest calls. Look for HttpWebRequest in CF.
http://msdn.microsoft.com/en-us/library/aa446517.aspx
Look at Microsoft's article Calling WCF Services.
To create your service, you are going to need to Power Toys for .NET Compact Framework 3.5, then turn around after installing that to Download the New NetCFSvcUtil (that is a direct download).
I've created Batch files that I store in my Services folder of my Windows Mobile Project (that way, I can't lose them). The batch file is like this:
** create.bat **
NetCFSvcUtil.exe /l:cs /o:Employee.cs /cb:ServiceModelBase http://cpweb2/mainframe/AcpEmployee.svc?wsdl
pause
NetCFSvcUtil.exe /l:cs /o:Packout.cs /cb:ServiceModelBase http://cpweb2/mainframe/AcpPackout.svc?wsdl
pause
That creates 2 Proxy files for me: One for Employees and one for my Packout service. They both create the same base file, ServiceModelBase, which is just a way for services to throw exceptions.
Adding the pause between steps enables you to read any error messages that are thrown up on the screen before running the next command.