Spring cloud config server on refresh -> logback config also refresh automatically - spring

I can't find any existing article/documentation related to this. The spring cloud config server and logback XML configuration are working in harmony, whenever I change something in my git repo config and trigger refresh of my application, somehow the logback automatically gets updated even though the logback is not in the config server but in the jar file itself.
Basically, my configuration is something like this:
I have an SMTP appender in my logback XML, at startup I'm checking if the enableSMTP is enabled, then I only set the recipient.
<if condition='property("smtpEnabled").equals("true")'>
<then>
<to>to#to.com</to>
</then>
</if>
This is to prevent email sending if the property is disabled, then I'm setting it back programmatically, ideally in EnvironmentChangeEvent. However, changing the property in the config server and calling the /monitor endpoint from the spring cloud config server to push an event to the cloud bus automatically sets this value in logback without programmatically setting it through the event handler.
Is this behavior of environment change and auto reconfigure of logback expected? (note that logback scan is disabled)

Related

Spring boot Redis cache TTL property change on the fly

is it possible to change the TTL property of Redis cache during the runtime if the same property has been changed in app config server? is there a way to automate the process to refresh the Redis instance properties during runtime on the event of config server change?
If you want to get the latest property in Config Server, it is recommended to do it through the client polling method, which can be found at
https://learn.microsoft.com/en-us/azure/spring-apps/how-to-config-server#config-server-refresh
Regarding the load to Redis instances, you may need to write some code to send out the event.

Spring Config Server with Spring Boot Properties

I am storing application.properties file in my config server. And my client applications are refering config server to download the property files.
Scenario 1:
When i change the value of property server.port in my config server. Can i reflect the changes in my client applicaiton without restarting the application.
You can use #RefreshScope beans for this purpose, this is not ideal but as close as you can get in config server, this is a pretty advanced thing after all.
So beans marked with this annotations will cause spring to clear the internal cache of the beans / configuration classes upon EnvironmentChangeEvent, then the instance of the bean will be created next time you'll try to call this bean.
To trigger such an event when the config server changes you can either explicitly call the actuator's refresh enpoint or develop your own solution that might be based on some messaging system so that the config server will be a producer of a "change" message and the consumer will be your application.
Now I can't say for sure whether it will work in particular with server.port, I've personally never seen a need to change this property, but for your custom beans this method will do the job.
Here is a good tutorial about this topic

How to disable Atomikos logfile when running Spring Boot with Atomikos JTA

I am using Spring Boot with Atomikos with embeded undertow server.I will be running my application in docker as a executable jar.We are writing all our logs as Sysout basically we are flushing and not writing any log files.But Atomikos is creating 3 log files when start and run application under my working directory.
How to disable creation of this log files. We should not create any physical log files in Disk.
or
Is there any way I can make these logs will be written in console instead of creating physical file.
Tried below configuration but it's not working.
com:
atomikos:
icatch:
enable_logging=false
You should run with -Dcom.atomikos.icatch.enable_logging=false as Atomikos itself does not read your application.yml so it will not read properties from there. Spring doesn't set this property either. A bit warning though, right from Atomikos documentation:
Specifies if disk logging should be enabled or not. Defaults to true.
It is useful for JUnit testing, or to profile code without seeing the
transaction manager's activity as a hot spot but this should never be
disabled on production or data integrity cannot be guaranteed.
Transaction logs are as important as data as they're used to recover from failures.

Spring Cloud Bus not working /bus/refresh call goes to controller and searching mapping in controller and failing

I have configured my application with config server and github supported external config files. It works fine when I am having single instance of my application in cloud foundry.
But for multiple instance it is said to implement spring cloud bus to apply external config changes to all the instances. For this I have bind my config server with rabbit MQ instance available on Pivotal Cloud foundry. have added spring.cloud.starter.bus.amqp jar in my build.gradle file.
Problem: But when I am hitting POST request to client app at:
http://server:port/bus/refresh the call goes to controller rather than refreshing all the instances and failing as no mapping for same.
Please let me know if I am missing any configuration to make spring-cloud-bus work.
Thanks in advance!
application.properties(Client application):
spring.profiles=cloud
spring.rabbitmq.host= 10.17.128.102
spring.rabbitmq.port= 5672
spring.rabbitmq.virtual-host= *****
spring.rabbitmq.username= ******
spring.rabbitmq.password= *****
rabbit.exchangeName= demoPartyServiceexc
rabbit.routingKey= demoPartyService
rabbit.queueName= demoPartyServicequeue
logging.level.ROOT= ERROR
bootstrap.properties(Client application):
spring.application.name=demo-api
spring.cloud.bus.enabled=true
spring.cloud.config.bus.enabled=true
spring.cloud.bus.amqp.enabled=true
spring.cloud.bus.refresh.enabled=true
spring.cloud.bus.env.enabled=true
spring.cloud.config.uri=https://config-a5e99419-8179-47f7-8c23-62ed5b38db0b.cf.com
spring.cloud.config.server.bootstrap=true
spring.cloud.config.server.git.uri= My Github repository URI
spring.cloud.config.server.git.username= ********
spring.cloud.config.server.git.password= ********
application.properties file in GIT repo:
logging.level.ROOT=WARN
What are server.servlet-path and management.context-path in client app set to?
I think you might need to send the request to http://host/<management.context-path>/bus/refresh.
Or better yet, to http://config-server-host/monitor so that it publishes a message to a topic in RabbitMQ and all client apps get notified.
Configuration snippets, source code and more details could be found at my blog post: Refreshable Configuration using Spring Cloud Config Server, Spring Cloud Bus, RabbitMQ and Git

Strange behavior with log4j2 configuration

I am working with spring cloud and log4j2 with "all" as level.
I will describe two situations with the same config file, I want to write on a Syslog TCP.
First test: I puth my log4j2 config file in resources folder, then, I start my app and start logging to the syslog.
But I need my configuration on a git, so I expose it to an url.
So here comes the second test:
I changed my bootstrap.yml and and the followind line:
logging: config:
http://xxx.xx.xx.75:3000/admin123/config-repository/raw/master/log4j2.xml
Then, I started my app and it starts to write the logging lines of spring boot in my syslog, but, when I put:
LOGGER.info("printing lalala");
Nothing is writed in the syslog and I can see a [FIN, ACK] beetween client and server on my TCP connections.
So, I understand that the config file is readed from the repository, becouse I can see it in my connections capture and becouse the app starts to log on syslog some lines, but something happend after that to close connection and write no more.
I can`t understand what is happening.
You must add the path of the logging.config on the application.yml not the bootstrap.yml and it works.

Resources