Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyamqp won't send heartbeat? #396

Open
Hoohaha opened this issue Jun 23, 2022 · 0 comments
Open

pyamqp won't send heartbeat? #396

Hoohaha opened this issue Jun 23, 2022 · 0 comments

Comments

@Hoohaha
Copy link

Hoohaha commented Jun 23, 2022

pyamqp==5.1.1

I used below sample code for testing.
If set heartbeat, the connection will be killed by rabbitmq server.

If disable heartbeat by set zero value, the code works very well.

Seems pyamqp won't send heartbeat automatically.

But if no heartbeat the rabbitmq won't close died connections, it cause server performance if too many dided connections.

import amqp
import time
import logging

def _on_message(*args, **kwargs):
	pass

def main():
	connection = amqp.Connection(host = 'xxx.xxx.xxx.xxx:5672', heartbeat = 3, userid="xxx", password="xxx")
	connection.connect()
	channel = connection.channel()

	queue = channel.queue_declare(queue = 'myqueue', durable = False, auto_delete = False)
	queue_name = queue.queue
	channel.exchange_declare('myex', type='direct', durable = False, auto_delete = False)

	channel.queue_bind(queue_name, 'myex', 'myroutingkey')
	channel.basic_qos(prefetch_size = 0, prefetch_count = 2, a_global = False)
	channel.basic_consume(callback = _on_message, queue = queue_name)
	print("xxxxxxxxxxxxxxxxxxxxxx")

	try:
		while True:
			connection.drain_events()
			time.sleep(0.5)
	except KeyboardInterrupt:
		logging.info("Python service stoped...........^v^")
		# Someone pressed CTRL-C, stop consuming and close
	except Exception as ex:
		logging.critical(ex)
	finally:
		channel.close()
		connection.close()

main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant