Skip to content

Commit

Permalink
Merge pull request #119 from beer-garden/issue/118
Browse files Browse the repository at this point in the history
Using heartbeat instead of deprecated heartbeat_interval
  • Loading branch information
loganasherjones committed Feb 24, 2019
2 parents 61eb6e6 + 57110dc commit c45d98e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
29 changes: 25 additions & 4 deletions brewtils/queues.py
Expand Up @@ -6,7 +6,27 @@


class PikaClient(object):
"""Base class for connecting to RabbitMQ using Pika"""
"""Base class for connecting to RabbitMQ using Pika
Args:
host: RabbitMQ host
port: RabbitMQ port
user: RabbitMQ user
password: RabbitMQ password
connection_attempts: Maximum number of retry attempts
heartbeat: Time between RabbitMQ heartbeats
heartbeat_interval: DEPRECATED, use heartbeat
virtual_host: RabbitMQ virtual host
exchange: Default exchange that will be used
ssl: SSL Options
blocked_connection_timeout: If not None, the value is a non-negative timeout,
in seconds, for the connection to remain blocked (triggered by
Connection.Blocked from broker); if the timeout expires before connection
becomes unblocked, the connection will be torn down, triggering the
adapter-specific mechanism for informing client app about the closed
connection (e.g., on_close_callback or ConnectionClosed exception) with
`reason_code` of `InternalCloseReasons.BLOCKED_CONNECTION_TIMEOUT`.
"""

def __init__(
self,
Expand All @@ -20,13 +40,14 @@ def __init__(
exchange="beer_garden",
ssl=None,
blocked_connection_timeout=None,
**kwargs
):
self._host = host
self._port = port
self._user = user
self._password = password
self._connection_attempts = connection_attempts
self._heartbeat_interval = heartbeat_interval
self._heartbeat = kwargs.get("heartbeat", heartbeat_interval)
self._blocked_connection_timeout = blocked_connection_timeout
self._virtual_host = virtual_host
self._exchange = exchange
Expand Down Expand Up @@ -85,8 +106,8 @@ def connection_parameters(self, **kwargs):
connection_attempts=kwargs.get(
"connection_attempts", self._connection_attempts
),
heartbeat_interval=kwargs.get(
"heartbeat_interval", self._heartbeat_interval
heartbeat=kwargs.get(
"heartbeat", kwargs.get("heartbeat_interval", self._heartbeat)
),
blocked_connection_timeout=kwargs.get(
"blocked_connection_timeout", self._blocked_connection_timeout
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Expand Up @@ -3,7 +3,7 @@
lark-parser < 0.7
marshmallow < 3
marshmallow-polyfield < 4
pika < 0.14
pika < 0.14, >= 0.11
pyjwt < 2
requests < 3
simplejson < 4
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@ def find_version():
"lark-parser<0.7",
"marshmallow<3",
"marshmallow-polyfield<4",
"pika<0.14",
"pika<0.14,>=0.11",
"pyjwt<2",
"requests<3",
"simplejson<4",
Expand Down
11 changes: 11 additions & 0 deletions test/queues_test.py
Expand Up @@ -23,6 +23,17 @@ def test_connection_parameters(self, client):
params = client.connection_parameters(host="another_host")
assert params.host == "another_host"
assert params.port == port
assert params.heartbeat == 3600

def test_connection_parameters_heartbeat(self, client):
assert client.connection_parameters(heartbeat=100).heartbeat == 100
assert client.connection_parameters(heartbeat_interval=100).heartbeat == 100
assert (
client.connection_parameters(
heartbeat=100, heartbeat_interval=200
).heartbeat
== 100
)

def test_connection_url(self, client):
url = client.connection_url
Expand Down

0 comments on commit c45d98e

Please sign in to comment.