Autoreconnect on failed database connection - quarkus

Quarkus give possibility to configure reconnection on failed acquire for reactive connection through config properties
quarkus.datasource.reactive.reconnect-attempts
quarkus.datasource.reactive.reconnect-interval
And I am searching how to get same functionality for non-reactive connections.
My first idea was to make reconnections through playing with AgroalDataSourceListener, but developers rejected idea of injecting listeners. Inject of AgroalPoolInterceptors was chosen instead. But by looking at interface of interceptor, it looks like interceptor it is not something that help with my problem.
So do you have any idea how to force AgroalCP to reconnect to datasource infinetely?

Related

Registration of dynamic websocket at application initialization time and at runtime has different endpoints exposed

I am trying to register websocket dynamically.For instance, i have registered '/sampleEndpoint' at runtime so ServerWebSocketContainer will register it and start publishing data on that endpoint. But now if i do the same process during application initialization time in PostConstruct than i am unable to connect to '/sampleEndpoint' but have to append '/websocket' at the end so url become '/sampleEndpoint/websocket' when connecting from client side. Why we are getting different endpoints at different situations?
I have attached github url to the code.
https://github.com/pinkeshsagar-harptec/code-sample.git
Well, that's how that SockJS option works: https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#websocket-fallback.
If you client is not SockJS, then you have to add that /websocket sub-path.
Not sure though why it doesn't work for dynamically registered endpoints...
In the case of #PostConstruct it is not dynamic: we still do the stuff within configuration phase of the application context, so it is able to add our endpoint into a static HandlerMapping. The dynamic nature is applied a bit later, when all the #PostConstruct have done their logic. You don't need to start that flow registration manually though since the auto-startup phase has not passed yet withing #PostConstruct handling.
Re. IntegrationDynamicWebSocketHandlerMapping: it sounds more like a bug and I need to investigate more. I guess you still use there that SockJS option and it has to be applied for dynamic endpoint as well.
Thank you for your patience! I'll investigate and fix it ASAP.
UPDATE
The fix is here: https://github.com/spring-projects/spring-integration/pull/3581.

Should I use #PostContruct or Context refresh event to connect to CTI server

I am developing a REST service which will connect to a CTI server through TCP and the connection will be kept opened until the my REST service is running.
Currently I am reading the server parameters from properties file and creating bean, after the bean is constructed, the server connection will be initiated using #PostConstruct. Is it good to use #PostConstruct for this scenario or should I use context refresh event.
I tested application using both #PostConstruct and context refresh, both are working good how ever I want to follow the best practices.
Note : I searched the forum and got some answers, but not related to my scenario
Technically there is no difference. You have already tested that part. I think #PostConstruct makes more sense mainly because the connection you are creating is specific to this bean. Creating a new ApplicationContextListener wouldn't make much sense as the connection is not at a context level.

hikaricp get number of busy connection

Like we can get the number of busy connection in c3p0 by using method like dataSource.getNumBusyConnections(), the same way how can we do that in case of hikaricp? Can anyone provide all the related methods between c3p0 and hikaricp? Also what is the destroy (in c3p0) method equivalent in hikaricp?
Re: connections, see these wiki pages:
JMX Monitoring (via console and programatically
Using Codahale/Dropwizard Metrics
HikariDataSource supports both close() and shutdown() methods, they are equivalent.
UPDATE: I put out a simple gist that uses JMX you can try.

Detecting disconnects using Spring messaging (websockets / STOMP)

We're using spring-messaging websocket with STOMP. Now we've defined multiple #SubscribeMapping methods, but is there also some sort of callback that gets fired when a client application disconnects from the socket?
We got a list of connect clients and some additional properties, like status. Status field needs to be updated when the client application disconnects.
Any suggestions on how to achieve this in Spring? I've tried implementing ApplicationListener however, there's no usefull information in the OnSessionDisconnect object.

Recover connection when using Spring JMSTemplate and ApacheMQ

//OVERVIEW//
I have a Java Swing Client that is pushing messages to a broker. For the producer, I am using the Spring SingleConnectionFactory:
org.springframework.jms.connection.SingleConnectionFactory
that is wrapped around an ActiveMQConnectionFactory:
org.apache.activemq.ActiveMQConnectionFactory
I am using the Spring JMSTemplate:
org.springframework.jms.core.JmsTemplate
to provide the mechanisms to send messages from the producer to the broker.
// PROBLEM //
Sometimes, the broker might go down, or the network might fail. When this happens, the only way I have been able to re-establish connection to the broker is to re-start the Swing application (producer) to re-initialize the components mentioned above.
Does anyone know how this might be done at run-time? Atempting to re-initialise beans at runtime sounds like a hack and I was wondering if there was a more elegant configuration option.
Thanks

Resources