env.StreamExists client retries #329
-
I am doing a code were I have to test if a stream exists or not. However when I call the method environment.Stream() and rabbitmq is down, then the connection keeps retrying forever, not sure if I am understanding that correctly. The above code is what I was looking to confirm it. func (env *Environment) newReconnectClient() (*Client, error) {
broker := env.options.ConnectionParameters[0]
client := newClient("go-stream-locator", broker, env.options.TCPParameters,
env.options.SaslConfiguration, env.options.RPCTimeout)
err := client.connect()
tentatives := 1
for err != nil {
sleepTime := rand.Intn(5000) + (tentatives * 1000)
logs.LogError("Can't connect the locator client, error:%s, retry in %d milliseconds, broker: ", err, sleepTime,
client.broker)
time.Sleep(time.Duration(sleepTime) * time.Millisecond)
rand.Seed(time.Now().UnixNano())
n := rand.Intn(len(env.options.ConnectionParameters))
client = newClient("stream-locator", env.options.ConnectionParameters[n], env.options.TCPParameters,
env.options.SaslConfiguration, env.options.RPCTimeout)
tentatives = tentatives + 1
err = client.connect()
}
return client, client.connect()
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The client tries to auto-reconnect automatically. The function should continue to work and exit when the broker is up. |
Beta Was this translation helpful? Give feedback.
-
RabbitMQ should always be up and running. If you could please explain the test you are doing, we can help. |
Beta Was this translation helpful? Give feedback.
-
I was just expecting that not to be a block call, until rabbitmq comes back. But that solves my doubts. Thanks. |
Beta Was this translation helpful? Give feedback.
The client tries to auto-reconnect automatically. The function should continue to work and exit when the broker is up.