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

heartbeat support for AMQP #189

Closed
zstyblik opened this issue Aug 6, 2014 · 7 comments · Fixed by #2676
Closed

heartbeat support for AMQP #189

zstyblik opened this issue Aug 6, 2014 · 7 comments · Fixed by #2676

Comments

@zstyblik
Copy link

zstyblik commented Aug 6, 2014

Please,

either enable or make configurable heartbeat in mod AMQP. This should be configurable and/or enabled.

https://github.com/balabit/syslog-ng-3.5/blob/master/modules/afamqp/afamqp.c#L334
https://github.com/omniti-labs/Net--RabbitMQ/blob/master/amqp.h#L234

Thank you.

[Edited by @Kokan]

As rabbitmq already supports heartbeat, from syslog-ng side it only has to make it configurable. For details see amqp_login function.

@algernon algernon self-assigned this Aug 14, 2014
@algernon
Copy link
Contributor

As far as I understand, just setting that option to some configurable value would not be enough, syslog-ng would need to send heartbeat packets too, if there's no other traffic. Doing that is a bit more involved than adding a configurable parameter.

Am I seeing it correctly? Or is it enough to set that argument, and receive heartbeat frames from the server, without sending any ourselves?

@zstyblik
Copy link
Author

I'm not familiar with C/C++ implementation of AMQP and higher-level languages do this for you. So it really is hard to tell. One thing, though. You must not block indefinitely and must keep polling. Otherwise, you might miss communication from MQ server which ultimately(?) leads to being kicked out and connection terminated.

@zstyblik
Copy link
Author

Am I seeing it correctly? Or is it enough to set that argument, and receive heartbeat frames from the server, without sending any ourselves?

Actually, I believe server itself doesn't send any heartbeats and it's up to client to send those.

@zstyblik
Copy link
Author

https://stackoverflow.com/questions/21020945/how-to-enable-server-side-heartbeat-for-rabbitmq <<< not exactly reliable source, but I guess it makes sense. If server doesn't hear from client in defined/agreed heartbeat, then it proclaims client to be dead and will close connection.

@algernon
Copy link
Contributor

Mmmhm. That's a bit harder to implement, but I have an idea: using ivykis timers might just get the job done in a neat way.

@ihrwein
Copy link
Contributor

ihrwein commented Mar 9, 2015

@dnsjts could you look at this?

@nvxxu2i nvxxu2i self-assigned this Mar 13, 2015
@aneutrals aneutrals removed this from the syslog-ng 3.7.1 milestone Aug 4, 2015
@presidento presidento removed the help label Jun 23, 2017
@Kokan Kokan changed the title enable heartbeat in mod AMQP heartbeat support for AMQP Mar 19, 2019
@furiel
Copy link
Collaborator

furiel commented Apr 5, 2019

As a hint, here is how I created a working environment for development. With better understanding of rabbitmq, there is probably a simpler way. Please share if you know one!

  1. Starting rabbitmq server from dockerhub.
$ docker run --name rabbitmq --net=host -ti rabbitmq
  1. Adding logs exchange for vhost "/".
    For some reason the default "" exchange did not work with the example script from the rabbitmq tutorial, so I needed to create another one.
  • Enable webui:
docker exec -ti rabbitmq rabbitmq-plugins enable rabbitmq_management

This will start a web service on http://localhost:15672

  • Add exchange:
    In the webui with guest:guest. On the Exchanges tab, fill the form
    name: logs
    type: fanout
    durability: transient
    (rest with default value)
    Add exchange.
  1. start syslog-ng with the configuration example below. Comment out example-msg-generator() if you do not want periodic messages.
@version: 3.20

log {
    source { stdin(flags(no-parse)); };
    source { example-msg-generator(); };
    destination { amqp(vhost("/")
                  exchange("logs")
                  body("hello world")
                  username(guest) password(guest)); };
};

To read logs, one can use the python snippet provided in the rabbitmq tutorial:

#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

exchange="logs"

channel.exchange_declare(exchange=exchange, exchange_type='fanout')

result = channel.queue_declare('', exclusive=True)
queue_name = result.method.queue

channel.queue_bind(exchange=exchange, queue=queue_name)

print(' [*] Waiting for logs. To exit press CTRL+C')

def callback(ch, method, properties, body):
    print(" [x] %r" % body)

channel.basic_consume(
    queue=queue_name, on_message_callback=callback, auto_ack=True)

channel.start_consuming()

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

Successfully merging a pull request may close this issue.

8 participants