sstone / amqp-client

[THIS PROJECT HAS BEEN ARCHIVED AND IS NO LONGER MAINTAINED] Simple fault-tolerant AMQP client written in Scala and based on Akka and the RabbitMQ java client
MIT License
161 stars 88 forks source link

Keepalive Support #54

Closed henricook closed 10 years ago

henricook commented 10 years ago

Hi guys,

I'm using amqp-client in quite a large Amazon deployment, one of the things i see most regularly in my logs is big ugly connection lost messages where the amazon load balancers have killed off my connection to RabbitMQ (my MQ of choice). The connections get reestablished of course but it's probably not good for overall efficiency (or disk space on my logging platform :p).

The Pika for python libraries support a 'keepalive' parameter which stops this happening when i use them to listen, do you have any plans to support keepalive in amqp-client?

Cheers,

Henri

sstone commented 10 years ago

Hi, If your problem is related to idle connections being closed by AWS load-balancers then AMQP heartbeats might be what you're looking for. You can specify heartbeat request delays when you create a connection with the ConnectionFactory.setRequestedHeartbeat (default is 0). Thanks

henricook commented 10 years ago

Very cool to know the support is in there thanks. I should no doubt research this next question myself, but i'm using an Akka actor as a consumer and instantiating it with:

conn(context).createConsumer(exchange, queueParams, routingKey, self, Some(channelParams), autoAck)

How might i apply the heartbeat parameter to this?

Cheers,

Henri

On 25 July 2014 17:13, sstone notifications@github.com wrote:

Hi, If your problem is related to idle connections being closed by AWS load-balancers then AMQP heartbeats might be what you're looking for. You can specify heartbeat request delays when you create a connection with the ConnectionFactory.setRequestedHeartbeat (default is 0). Thanks

— Reply to this email directly or view it on GitHub https://github.com/sstone/amqp-client/issues/54#issuecomment-50170788.

-------------------------------------- Henri Cook Senior Software Developer Technical Lead - Content Services

http://www.rightster.com

Rightster Plc | Third Floor, 1 Neal Street, London, WC2H 9QL

henricook commented 10 years ago

conn(context) returns a RabbitMQConnection object from amqp-client

On 25 July 2014 17:18, Henri Cook henri.cook@rightster.com wrote:

Very cool to know the support is in there thanks. I should no doubt research this next question myself, but i'm using an Akka actor as a consumer and instantiating it with:

conn(context).createConsumer(exchange, queueParams, routingKey, self, Some(channelParams), autoAck)

How might i apply the heartbeat parameter to this?

Cheers,

Henri

On 25 July 2014 17:13, sstone notifications@github.com wrote:

Hi, If your problem is related to idle connections being closed by AWS load-balancers then AMQP heartbeats might be what you're looking for. You can specify heartbeat request delays when you create a connection with the ConnectionFactory.setRequestedHeartbeat (default is 0). Thanks

— Reply to this email directly or view it on GitHub https://github.com/sstone/amqp-client/issues/54#issuecomment-50170788.

-------------------------------------- Henri Cook Senior Software Developer Technical Lead - Content Services

http://www.rightster.com

Rightster Plc | Third Floor, 1 Neal Street, London, WC2H 9QL

-------------------------------------- Henri Cook Senior Software Developer Technical Lead - Content Services

http://www.rightster.com

Rightster Plc | Third Floor, 1 Neal Street, London, WC2H 9QL

sstone commented 10 years ago

Unfortunately you cannot set heartbeats when you create connections with RabbitMQConnection , which has been removed from recent versions of the library. It was just a simple wrapper on top of connection actors, which you can create directly from ConnectionFactory objects.

So, instead of : val conn = new RabbitMQConnection(host = "localhost", name = "Connection") val consumer = conn.createChild(Props(new Consumer(listener = Some(listener))))

You would now write: val connFactory = new ConnectionFactory() connFactory.setUri("amqp://guest:guest@localhost/%2F") // for example connFactory.setRequestedHeartbeat(30)

val conn = system.actorOf(ConnectionOwner.props(connFactory, 1 second)) val consumer = ConnectionOwner.createChildActor(conn, Consumer.props(listener, channelParams = None, autoack = false))

And have conn(context) return a ConnectionOwner actor instead of a RabbitMQConnection object.

Thanks (and sorry for the trouble)

henricook commented 10 years ago

Amazing, thanks for taking the time to give such a detailed response! I'll try it immediately!

On 25 July 2014 17:38, sstone notifications@github.com wrote:

Unfortunately you cannot set heartbeats when you create connections with RabbitMQConnection , which has been removed from recent versions of the library. It was just a simple wrapper on top of connection actors, which you can create directly from ConnectionFactory objects.

So, instead of : val conn = new RabbitMQConnection(host = "localhost", name = "Connection") val consumer = conn.createChild(Props(new Consumer(listener = Some(listener))))

You would now write: val connFactory = new ConnectionFactory() connFactory.setUri("amqp://guest:guest@localhost/%2F") // for example connFactory.setRequestedHeartbeat(30)

val conn = system.actorOf(ConnectionOwner.props(connFactory, 1 second)) val consumer = ConnectionOwner.createChildActor(conn, Consumer.props(listener, channelParams = None, autoack = false))

And have conn(context) return a ConnectionOwner actor instead of a RabbitMQConnection object.

Thanks (and sorry for the trouble)

— Reply to this email directly or view it on GitHub https://github.com/sstone/amqp-client/issues/54#issuecomment-50173805.

-------------------------------------- Henri Cook Senior Software Developer Technical Lead - Content Services

http://www.rightster.com

Rightster Plc | Third Floor, 1 Neal Street, London, WC2H 9QL

sstone commented 10 years ago

You're welcome!