Is there a mechanism in spring-retry that persist retries during restarts?
I would need that for a spring-boot application deployed in tomcat.
Edit:
As an alternative I would see a queue or quartz-scheduler as solution
You can do it but you would have to implement a custom RetryContextCache that persists the retry state to some backing store. You would then inject your custom cache into the RetryTemplate.
Related
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.
I wanted to run my Grails application (version 4.0.4) in a cluster. I tried to apply Hazelcast to replicate the HTTP session across the nodes/instances but somehow I couldn’t override/replace the SessionRepository bean that Grails uses with the Hazelcast implementation.
My working configuration in Spring Boot is: I declare the Hazelcast bean and annotate the Application with #EnableHazelcastHttpSession which in turn introduces the new SessionRepository from Hazelcast.
But I couldn’t make this configuration work in Grails and override the SessionRepository. (Although the app starts, it acts very strange.)
Any ideas?
Or do you suggest an alternative approach to implement a distributed session in Grails? How did you replicate session from your past experience?
(P.S The reason I chose Hazelcast is, since it is a distributed cache which can be embedded with the application itself, I can avoid dependency on external service such as Redis, to run the app. That is part of the requirement).
Thank you.
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
I'm reading through the docs here https://docs.spring.io/spring-kafka/docs/2.2.6.RELEASE/reference/html/#retrying-deliveries and I cannot figure out what the correct way is for implementing stateful retry with a batch listener
The docs say that a "retry adapter is not provided for batch message listeners because the framework has no knowledge of where in a batch the failure occurred".
This is not a problem for my use case as I want to just retry the whole batch.
The docs recommend that I use a RetryTemplate within the listener itself. Ok, I can do that.
The problem comes in the next section where it discusses using the stateful retry flag to make the consumer poll between retries in order to prevent the broker from dropping my consumer.
How do I configure a batch listener to do that? Is the stateful retry flag supported for batch listeners? If My retry logic is in within the listener itself, wouldn't that prevent the polling? What exactly does the statefulRetry flag even do?
The latest version of spring kafka has a special RetryingBatchErrorHandler. https://docs.spring.io/spring-kafka/docs/2.4.6.RELEASE/reference/html/#retrying-batch-eh Thanks, Spring Kafka Team!
No; you can't add a RetryTemplate to the container factory for a batch listener.
java.lang.ClassCastException: org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter cannot be cast to org.springframework.kafka.listener.MessageListener
We will clean that up with a more meaningful error..
With the upcoming 2.3 release (release candidate currently due next Friday) you can add a BackOff to the SeekToCurrentErrorHandler which provides similar functionality to the RetryTemplate; with current releases, the redelivery will be attempted immediately.
Furthermore, another new feature recently merged provides a mechanism to retry from a specific index in a batch.
Is there a way in spring boot to control the graceful shutdown of the app.
I know that you can have #PreDestroy methods in beans but how can you control the ordering in which those #PreDestroy methods are called.
You can have multiple beans depending on each other will the shutdown of the context look for this dependency already and call the #PreDestroy methods in the right order or not?
For example what I would like to accomplish is:
1.) stop listening for new requests on rest endpoints
2.) prevent rabbit message listeners to accept new messages
3.) wait for all processing that has started before the shutdown but is not finished yet.
Spring-boot-2-3-0 has added support for graceful shutdown.
you can enable graceful shutdown by setting up server.shutdown=graceful property
To configure the timeout period you can use
spring.lifecycle.timeout-per-shutdown-phase=20s
spring boot documentation
If you can not upgrade to spring boot 2.3 then you can check below project
https://github.com/gesellix/graceful-shutdown-spring-boot