Skip to content

Commit

Permalink
Merge pull request vklochan#51 from matt-snider/allow-passive-amqp
Browse files Browse the repository at this point in the history
Allow exchange to be declared passively in AMQPLogstashHandler
  • Loading branch information
vklochan committed Jun 9, 2016
2 parents a7c5dd2 + e996c11 commit 890e043
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions logstash/handler_amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class AMQPLogstashHandler(SocketHandler, object):
:param exchange_type: AMQP exchange type (default 'fanout').
:param durable: AMQP exchange is durable (default False)
:param virtual_host: AMQP virtual host (default '/').
:param passive: exchange is declared passively, meaning that an error is
raised if the exchange does not exist, and succeeds otherwise. This is
useful if the user does not have configure permission on the exchange.
:param tags: list of tags for a logger (default is None).
:param message_type: The type of the message (default logstash).
Expand All @@ -43,8 +46,8 @@ class AMQPLogstashHandler(SocketHandler, object):
def __init__(self, host='localhost', port=5672, username='guest',
password='guest', exchange='logstash', exchange_type='fanout',
virtual_host='/', message_type='logstash', tags=None,
durable=False, version=0, extra_fields=True, fqdn=False,
facility=None, exchange_routing_key=''):
durable=False, passive=False, version=0, extra_fields=True,
fqdn=False, facility=None, exchange_routing_key=''):


# AMQP parameters
Expand All @@ -55,6 +58,7 @@ def __init__(self, host='localhost', port=5672, username='guest',
self.exchange_type = exchange_type
self.exchange = exchange
self.exchange_is_durable = durable
self.declare_exchange_passively = passive
self.virtual_host = virtual_host
self.routing_key = exchange_routing_key

Expand All @@ -81,6 +85,7 @@ def makeSocket(self, **kwargs):
self.exchange,
self.routing_key,
self.exchange_is_durable,
self.declare_exchange_passively,
self.exchange_type)

def makePickle(self, record):
Expand All @@ -90,7 +95,7 @@ def makePickle(self, record):
class PikaSocket(object):

def __init__(self, host, port, username, password, virtual_host, exchange,
routing_key, durable, exchange_type):
routing_key, durable, passive, exchange_type):

# create connection parameters
credentials = pika.PlainCredentials(username, password)
Expand All @@ -104,6 +109,7 @@ def __init__(self, host, port, username, password, virtual_host, exchange,
# create an exchange, if needed
self.channel.exchange_declare(exchange=exchange,
exchange_type=exchange_type,
passive=passive,
durable=durable)

# needed when publishing
Expand Down

0 comments on commit 890e043

Please sign in to comment.