I am using Wildfly and I started to write some clients to connect to other backends. Now I want to set some timeouts to my stubs to avoid that my application performance suffers from slow or not responding backends.
The connection works very well, but when I wanted to set the timeout I realized that I have to fall back to the client implementation so I used resteasy (used in Wildfly afaik).
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.8.Final</version>
<scope>provided</scope>
</dependency>
Is there really no standard way to accomplish that?
The resteasy documentation is quite short. Does anyone have a good source with examples for setting a timeout there?
greetings
m
PS:
Client client = ClientBuilder.newClient();
Builder request = client.target(ADRESS_BALANCE).request();
return request.get(BigInteger.class);
RestEasy way to set socketTimeout:
ResteasyClientBuilder builder = (ResteasyClientBuilder) ClientBuilder.newBuilder();
builder.socketTimeout(60, TimeUnit.SECONDS);
If you would like to use standard way check this answer
Related
I have introduced LRA on a MicroProfile application already running on WildFly AS.
To get the LRA working I have added the following depedency on my application pom.xml
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>narayana-lra</artifactId>
<version>5.10.6.Final</version>
</dependency>
and I have created an LRA coordinator running on the same host ad listening on port 8080.
The application works as expected.
Now I want to move LRA coordinator on a remote host, but I'm not able to configure my application to point to it (on new host and port).
I have tried to put in my microprofile-config.properties the following parameters:
mp.lra.http.host=<new_host>
mp.lra.http.port=<new_port>
but without effect.
Can anyone suggest me hot to configure LRA coordinator host and port on client application?
Thanks in advance
Narayana doesn't support MicroProfile Config yet even if it is something that it probably should. The properties you want to set are defined only as system properties (i.e., read with System.getProperty(String, String).
Another issue is that the properties you are looking for are defined as lra.http.host and lra.http.port respectively. MP LRA made a deliberate decision to remove all coordinator references from the specification to not specify the implementation architectures (saga can also be implemented as an orchestration pattern).
So you need to set these system properties for instance when you are starting the WildFly server:
bin/standalone.sh -Dlra.http.host=lra-coordinator.com -Dlra.http.port=7777
Finally, if you ever move to the latest Narayana releases, these properties were merged only into single property lra.coordinator.url which is however still read only from system properties.
I deploy a native quarkus application under cloud run. This application need to connect to a cloud sql postgresql database.
On the configuration panel's cloud run, i create a Cloud SQL connections (db-instance-name eq. cloud sql) and some variable as DB_USER, DB_PASSWORD, DB_NAME
On Quarkus, i define properties as below :
quarkus.datasource.jdbc.url=jdbc:postgresql:///${DBNAME}:5432
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.username=${DB_USER}
quarkus.datasource.password=${DB_PASSWORD}
My pom.xml
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.0.16</version>
</dependency>
When cloud run is starting, an exception occured :
WARN [io.agr.pool] (Agroal_18109070341) Datasource '<default>': Connection to :5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections
I have to say that cloud run is deployed by cloud build.
Could you help me to fix this issue...
Thanks
You need to use a unix_socket file looks like the following
postgres://user:password#/databasename?unix_sock=/cloudsql/projectshortcod:us-central1:pg-instance-name
you probably need to put this in the URL field of you library, but make sure that the library supports unix_socket databases.
I got this working (for MySQL instead of Postgres; but should be similar) without using a unix_socket, but simply using a quarkus.datasource.jdbc.url=jdbc:mysql:///DB-NAME?ipTypes=PRIVATE&cloudSqlInstance=PROJECT-NAME:REGION:demo&socketFactory=com.google.cloud.sql.mysql.SocketFactory (and an quarkus.datasource.username= and quarkus.datasource.password=, as always).
The ?ipTypes=PRIVATE& is to connect to a Cloud SQL with only a private instead of a public IP from within GCP; omit that if you want to connect to a public IP, e.g. from your developer machine at home or work.
The trickiest part wasn't so much this but to set up all the required pre-requisites on GCP for this connection to work from a Quarkus service running on AppEngine Standard.
Quarkus Issue #9985 is for about documenting this.
This question already has answers here:
Spring Boot - How to log all requests and responses with exceptions in single place?
(28 answers)
Closed 3 years ago.
I have a Spring Boot backend application and I'd like to list all the REST API calls made by clients to my application.
I'm running my app in Tomcat/nginx.
Way 1 (Actuator):
You can track last 100 request using Spring Boot Actuator. Here is the way to do this :
Add the maven dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Edit the application.properties and add the following line:
management.endpoints.web.exposure.include=*
After running your spring boot application, now you can track the latest 100 http requests by calling this url:
http://localhost:8070/actuator/httptrace
Way 2 (Aspect):
But you can also get the log using Aspect.
It provide you some amazing annotation like: #Before , #AfterReturning, #AfterThrowing etc.
Here #Before log the url,request parameters, #AfterReturning log the response parameters and #AfterThrowing log the error with message, You may not don't need all endpoints log, so here have some filters based on package.
To implement this feature using aspects check this anawer
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 :-)
Is there an built in HTTP server in Apache CXF like "HttpServerFactory" of Jersey?
I tried reading through the CXF documentation but couldn't find anything similar.
Yes, there is.
If you want JAX-RS service deployed on built-in server use org.apache.cxf.jaxrs.JAXRSServerFactoryBean. Example usage (taken from CXF samples):
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CustomerService.class);
sf.setResourceProvider(CustomerService.class,
new SingletonResourceProvider(new CustomerService()));
sf.setAddress("http://localhost:9000/");
sf.create();
If you want JAX-WS service deployed on built-in server you can use javax.xml.ws.Endpoint.publish(..). Sample code (again copied from CXF Sample):
HelloWorldImpl implementor = new HelloWorldImpl();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, implementor);
Both JAX-WS and JAX-RS require adding org.apache.cxf:cxf-rt-transports-http-jetty to classpath.
I really recommend taking look at CXF samples. Sometimes they are indispensable.