Spring boot JedisConnectionFactory not loading settings from application.yml - spring-boot

I have a spring book (kotlin) app using Jedis to connect to redis.
Spring has documented a list of common connection properties for redis. My understanding from reading blog posts and documentation is that JedisConnectionFactory is expected to automatically read and respect those values.
Unfortunately it doesn't seem like this is happening in my code.
I would expect a connection failure with a default redis running on localhost and an application.yml as follows, but it isn't happening.
spring:
redis:
database: 0
host: localhostBadhost
port: 9999 #default is: 6379
password: badPassword
timeout: 60000
What steps need to be taken to ensure Jedis executes its auto-configuration step?

Related

Jetty Spring Boot with session replication

I am using spring boot 2.5.3 with Jetty 9.4.43.v20210629. I want to share the session across multiple nodes. In Jetty 9.4 there are lot of changes in session management. I want some reference materials for session replication (using JDBC / File system) with java configurations.
Session replication can be done using spring session with following storage options,
Hazlecast
Database
Redis
MongoDB
spring.session.store-type property should be used to decide the storage type. When multiple nodes / containers point to same storage it will share the session and no need to maintain a sticky session.
Need to add proper dependencies in pom.xml and add annotations when required (ex: #EnableJDBCHttpSession)
sample application yaml changes.
JDBC
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: jdbc
session.jdbc.initialize-schema: always
jpa.database: mysql
jpa.database-platform: org.hibernate.dialect.MySQL5Dialect
datasource.url: jdbc:mysql://mysqldb:3306/user
datasource.username: user
datasource.password: user1234#
datasource.driver-class-name: com.mysql.cj.jdbc.Driver
Redis
spring:
application.name: console-bs
main.allow-bean-definition-overriding: true
profile: default
session.store-type: redis
redis.host: redis
redis.port: 6379

Spring Cloud Config v3: Are the spring.cloud.config.retry - parameters no longer supported when using spring.config.import: "configserver:"?

I'm trying to upgrade to Spring Cloud 2020.0.0-RC1 and have started to use the new spring.config.import model.
But I can't get the retry mechanism to work anymore.
(as described here: https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#config-client-retry)
I have basically renamed my bootstrap.yml file to appliction.yml and added the line spring.config.import: "configserver:", like:
spring.config.import: "configserver:"
spring:
application.name: product
cloud.config:
failFast: true
retry:
initialInterval: 3000
multiplier: 1.3
maxInterval: 10000
maxAttempts: 20
It works fine to connect to a running config server, but if the config server is not yet started the client no longer retries to connect.
Are the spring.cloud.config.retry - parameters no longer supported when using spring.config.import: "configserver:"?
If not, is there some other way to retry connecting to the config server when using the new spring.config.import model?
Thanks for the bugfix in https://github.com/spring-cloud/spring-cloud-config/issues/1775, it solves the problem!
However, there seems to be a new related issue with corrupted log output. I have reported it in https://github.com/spring-cloud/spring-cloud-config/issues/1780.

Connection Pooling configuration with HikariCP and AWS Aurora Serverless

I am creating microservices applications using spring boot. All these microservices will connect to a single database AWS Aurora Serverless. I am planning to configure the connection pooling in my applications using HikariCP. Based on my initial research, Aurora Serverless manages connection pooling automatically. My question are the following.
Do I still need to configure connection pooling in my microservices using HikariCP? If yes, what is the recommended configuration in spring boot application.yml considering these are microservices that would share the same database?
If connection pooling configuration is not needed in my microservices, should i disable it? And, how should I do it my application.yml.
I have initial hikaricp configuration as shown in my code below
Springboot version is 1.5.7.RELEASE
application.yml
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
hikari:
connection-timeout: 30000
minimum-idle: 30
maximum-pool-size: 200
idle-timeout: 30000
... database details (url, password, etc...)
A connection pool is still useful since there will be a cost to build a connection from your app to their connection pool.
What is different is that when you don't have any activity during a significant amount of time (night/weekend/periods of no activity) or when speed is not a necessity you should put the minimum-idle parameter to zero.
This will make sure the number of connections goes down to zero and enable your aurora serverless db to go into pause.
When it is paused you pay only for storage costs.

hystrix.stream, management.port and Spring Cloud Turbine

My microservice with #EnableTurbine config:
turbine:
clusterNameExpression: new String('default')
appConfig: bestallning
bestallning is a #SpringCloudApplication, hystrix.stream is enabled. It registers in eureka and turbine app can find it. But it has management.port set to 8092 and server.port 8082. hystrix.stream binds to management.port
Turbine now tries to fetch hystrix.stream from server.port of bestallning, not management.port that hystrix.stream is bound to.
Fetching instance list for apps: [bestallning]
Fetching instances for app: bestallning
Received instance list for app: bestallning, size=1
Retrieved hosts from InstanceDiscovery: 1
Found hosts that have been previously terminated: 0
Hosts up:1, hosts down: 0
Url for host: http://143.237.21.196:8082/hystrix.stream default
Could not initiate connection to host, giving up: [{"timestamp":1460035761979,"status":404,"error":"Not Found","message":"No message available","path":"/hystrix.stream"}]
Stopping InstanceMonitor for: 143.237.21.196 default
Is it possible to have turbine look for hystrix.stream using the correct port?
I think you'd have to write your own InstanceDiscovery (and create a #Bean of that type). Might be a useful feature in the existing implementations though, so please open an issue in Spring Cloud Netflix.

Spring Cloud Turbine - Unable to handle multiple clients?

I’m having a bit of trouble getting Turbine to work in Spring Cloud. In a nutshell, I can’t determine how to configure it to aggregate circuits from more than one application at a time.
I have 6 separate services, a eureka server, and a turbine server running in standalone mode. I can see from my Eureka server that all of the services are registered, including turbine. My turbine server is up and running, and I can see its /hystrix page without issue. But when I try to use it to examine turbine.stream, I only see the FIRST server that is listed in turbine.appConfig, the rest are ignored.
This is my Turbine server’s application.yml, or at least the relevant parts:
---
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8010/eureka/
server:
port: 8030
info:
component: Turbine
turbine:
clusterNameExpression: new String(“default”)
appConfig: sentence,subject,verb,article,adjective,noun
management:
port: 8990
When I run this and access the hystrix dashboard on my turbine instance, asking for the turbine.stream, the ONLY circuit breakers listed in the output are for the first service listed in appConfig, the “sentence” service in this case. Curiously, if I re-arrange the order of these services and put another one first (like “noun”), I see only the circuits for THAT service. Only the first service in the list is displayed.
I’ll admit to being a little confused on some of the terminology, like streams, clusters, etc., so I could be missing some basic concept here, but my understanding is that Turbine could digest streams from more than one service and aggregate them in a single display. Suggestions would be appreciated.
I don't have enough reputation to comment, so I have to write this in an answer :)
I had the exactly same problem:
There are two services "test-service" and "other-service", each with it's own working hystrix-stream
and there is one Turbine-Application, which is configured like this:
turbine:
clusterNameExpression: new String("default")
appConfig: test-service,other-service
All of my services are running on my local machine.
Result is: My Hystrix-Dashboard just shows the metrics from "test-service".
Reason:
It seems to be, that a Turbine-Client which is configured the described way doesn't handle multiple services when they are running at the same host.
This is explained here:
https://github.com/Netflix/Hystrix/issues/117#issuecomment-14262713
Turbine maintains state of all these instances in order to maintain persistent connections to them and it does rely on the "hostname" and if the host name is the same then it won't instantiate a new connection to that same server (on a different port).
So the main point is, that all of your services must be registered with different hostnames. How you could do this on your local machine is described below.
UPDATE 2015-06-12/2016-01-23: Workaround for local testing
Change your hostfile:
# ...
127.0.0.1 localhost
127.0.0.1 localdomain1
127.0.0.1 localdomain2
# ...
127.0.0.1 localdomainx
And then set the hostname for your clients each to a different domain-entry like this:
application.yml:
eureka:
instance:
hostname: localdomainx

Resources