what is difference between connection timeout and session timeout in curator - session

when we create a curator client, we have
RetryPolicy retryPolicy = new RetryNTimes(3, 1000);
CuratorFramework client = CuratorFrameworkFactory.newClient(zkConnectString,
15000, // sessionTimeoutMs
15000, // connectionTimeoutMs
retryPolicy);
Can someone tell what is difference between session timeout and connection timeout in the above api call?
Thank you

You cannot make API calls to ZooKeeper until the connection has been established (i.e. until you get SyncConnected). Curator internally waits until this connection has been established for you. connectionTimeoutMs is the max time to wait for this.

Related

OKHttp request not stopping on define request timeout

I'm having trouble regarding okhttp not stopping/not closing on my define request timeout seconds. I set my connection timeout to 30 seconds on each timoeut (conenectTimeout, writeTimeout and readTimeout) but not closing. I do have a logs on my user that my request took more than an hour. Hoping someone can help me on this matter
builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)

ActiveMQ Connection is not working

I created the ActiveMQ Connection with ActiveMQConnectionFactory,
connectionFactory = new ActiveMQConnectionFactory("nio://0.0.0.0:" + activeMqPort);
connection = connectionFactory.createConnection();
connection.start();
Later some point of time I am using the connection to get the session:
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
While creating session from Connection it will fail with a NullPointerException (connection is null),
PS: Connection was working before, suddenly its null.
Can anyone explain it to me when this will happen and how to fix this ?
Your URI is incorrect for a client-side connection. nio:// is only relevant on the server-side, and specifying "0.0.0.0" is used by the server-side to instruct the server to listen on all ip interfaces.
Try this instead to connect to an ActiveMQ server running on the same computer as this client code:
connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:" + activeMqPort);
connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Bonus recommendations:
Externalize the entire client url, not just the port. This will allow you to specify multiple servers for failover, reconnect timeout parameters and other client connectivity settings that would otherwise require a code change.
Do not use CLIENT_ACKNOWLEDGE unless you really know what it does. Its is a source of a lot of pain and suffering if you don't clearly have a handle on how it works. If you want per-message Acknowledgement, use ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE. For non-transacted, use Session.AUTO_ACKNOWLEDGE.

Relation between PoolTimeout, IdleTimeout & IdleCheckFrequency in go-redis

Can someone let me know the relation between PoolTimeout, IdleTimeout & IdleCheckFrequency in go-redis?
Doubts:-
If I specify PoolTimeout 20ms, IdleTimeout 20ms, PoolSize 100 & IdleCheckFrequency 1 min. Let's say all the connection in the pool are used and a connection finishes its operation. Then will the request for a new connection wait till the IdleCheck is run in 1 min interval?
If I specify PoolSize 100 will the client keep open 100 connections to redis even if there is no active client operation being performed to Redis?
Environment:-
Go - 1.7.4
Redis - 3.2.6
Go-Redis - v5.2
This has been answered in github here. Just posting the relevant parts below:-
PoolSize limits max number of open connections. If app is idle then
go-redis does not open any connections.
New connection is opened when there is a command to process and there
are no idle connections in the pool. Idle connections are closed after
they are idle for IdleTimeout.
IdleCheckFrequency specifies how often we check if connection is
expired. This is needed in case app is idle and there is no activity.
Normally idle connections are closed when go-redis asks pool for a
(healthy) connection.

ActiveMQ - handle connection, session, producer and concumer opon failover

I do use failover transport feature by using the following pattern in the broker URL
failover:(tcp://host:port)
Init code goes as follow:
factory = new PooledConnectionFactory(BROKER_URL);
connection = factory.createConnection();
connection.start();
the put message code looks more or less like this:
session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );
Destination destQueue = new ActiveMQQueue(queue);
MessageProducer producer = session.createProducer(destQueue);
TextMessage msg = session.createTextMessage(message);
producer.send(msg);
When a failover occurs -
[org.apache.activemq.transport.failover.FailoverTransport] Transport (broker) failed, reason: , attempting to automatically reconnect: java.net.SocketException: recv failed: Connection aborted by peer
and got reconnected after
[org.apache.activemq.transport.failover.FailoverTransport] Failed to connect to [broker] after: 10 attempt(s) continuing to retry.
08:55:29,596 INFO [org.apache.activemq.transport.failover.FailoverTransport] Successfully reconnected to broker
do I have to reinitiate a connection? Or to be more specific, do I have to do anything with the connection object to be able to produce/consume message after the failover?
thanks
The whole point of the failover transport is to handle the reconnection for you. The logs you've shown indicate a successful reconnect cycle where the transport has continued to retry to connect to a broker and eventually did so.

Timeout for a listenning socket (Windows)

does anyone know if you can set a timeout for a listening socket?
I know that you can use a timeout for a send/recv action with SO_RCVTIMEO and SO_SNDTIMEO (through setsockopt) but in my case I need to set that timeout for a socket in a listen state. If no connection is established in X time, I closed the socket. Do you know any socket option to get that?
Thank you.
Yes, you can set SO_RCVTIMEO and it will timeout the accept() method.

Resources