From 25c9518fe2e82d552fbdb431b33c3a62b1bfc7a6 Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:21:57 +1100 Subject: [PATCH 1/6] feat: implement virtual host connection params --- config.schema.yaml | 3 +++ sensors/queues_sensor.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config.schema.yaml b/config.schema.yaml index c2f4e6c..42e1503 100644 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -16,6 +16,9 @@ sensor_config: description: "Optional password for RabbitMQ" type: "string" secret: true + virtual_host: + description: "Optional virtual host for RabbitMQ" + type: "string" rabbitmq_queue_sensor: description: "Queue settings" type: "object" diff --git a/sensors/queues_sensor.py b/sensors/queues_sensor.py index 95e8955..a5c12fa 100644 --- a/sensors/queues_sensor.py +++ b/sensors/queues_sensor.py @@ -30,6 +30,7 @@ def __init__(self, sensor_service, config=None): self.host = self._config["sensor_config"]["host"] self.username = self._config["sensor_config"]["username"] self.password = self._config["sensor_config"]["password"] + self.virtual_host = self._config["sensor_config"]["virtual_host"] if 'virtual_host' in self._config["sensor_config"].keys() else None queue_sensor_config = self._config["sensor_config"]["rabbitmq_queue_sensor"] self.queues = queue_sensor_config["queues"] @@ -77,6 +78,8 @@ def setup(self): ) else: connection_params = pika.ConnectionParameters(host=self.host) + if self.virtual_host: + connection_params.virtual_host = self.virtual_host self.conn = pika.BlockingConnection(connection_params) self.channel = self.conn.channel() From 869f6525957ba19e1fcc3124d373ed12065be433 Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:27:53 +1100 Subject: [PATCH 2/6] feat: update readme to include virtual_host --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2bef8d3..29962e0 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ and edit as required. * ``host`` - RabbitMQ host to connect to. * ``username`` - Username to connect to RabbitMQ (optional). * ``password`` - Password to connect to RabbitMQ (optional). +* ``virtual_host`` - RabbiqMQ virtual host to use (optional). * ``queues`` - List of queues to check for messages. See an example below. * ``quorum_queues`` - List of queues defined in `queues` that should be handled as `type: quorum` * ``deserialization_method`` - Which method to use to de-serialize the From 16550ac34d74090bad74c701ca14d1e3a7defc47 Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:31:43 +1100 Subject: [PATCH 3/6] refactor: match virtual host syntax --- README.md | 2 +- config.schema.yaml | 4 +++- sensors/queues_sensor.py | 8 +++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 29962e0..bda58c1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ and edit as required. * ``host`` - RabbitMQ host to connect to. * ``username`` - Username to connect to RabbitMQ (optional). * ``password`` - Password to connect to RabbitMQ (optional). -* ``virtual_host`` - RabbiqMQ virtual host to use (optional). +* ``virtual_host`` - RabbitMQ virtual host to use. * ``queues`` - List of queues to check for messages. See an example below. * ``quorum_queues`` - List of queues defined in `queues` that should be handled as `type: quorum` * ``deserialization_method`` - Which method to use to de-serialize the diff --git a/config.schema.yaml b/config.schema.yaml index 42e1503..88c6832 100644 --- a/config.schema.yaml +++ b/config.schema.yaml @@ -17,8 +17,10 @@ sensor_config: type: "string" secret: true virtual_host: - description: "Optional virtual host for RabbitMQ" type: "string" + description: "RabbitMQ virtual host to use" + required: true + default: "/" rabbitmq_queue_sensor: description: "Queue settings" type: "object" diff --git a/sensors/queues_sensor.py b/sensors/queues_sensor.py index a5c12fa..fb9e2f3 100644 --- a/sensors/queues_sensor.py +++ b/sensors/queues_sensor.py @@ -30,7 +30,7 @@ def __init__(self, sensor_service, config=None): self.host = self._config["sensor_config"]["host"] self.username = self._config["sensor_config"]["username"] self.password = self._config["sensor_config"]["password"] - self.virtual_host = self._config["sensor_config"]["virtual_host"] if 'virtual_host' in self._config["sensor_config"].keys() else None + self.virtual_host = self._config["sensor_config"]["virtual_host"] queue_sensor_config = self._config["sensor_config"]["rabbitmq_queue_sensor"] self.queues = queue_sensor_config["queues"] @@ -74,12 +74,10 @@ def setup(self): username=self.username, password=self.password ) connection_params = pika.ConnectionParameters( - host=self.host, credentials=credentials + host=self.host, credentials=credentials, virtual_host=self.virtual_host ) else: - connection_params = pika.ConnectionParameters(host=self.host) - if self.virtual_host: - connection_params.virtual_host = self.virtual_host + connection_params = pika.ConnectionParameters(host=self.host, virtual_host=self.virtual_host) self.conn = pika.BlockingConnection(connection_params) self.channel = self.conn.channel() From cfe023bc858c5fcf9491d3e39e9c2283406654f0 Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:38:12 +1100 Subject: [PATCH 4/6] fix: refactor to be flake8 E501 compliant --- sensors/queues_sensor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sensors/queues_sensor.py b/sensors/queues_sensor.py index fb9e2f3..7270be2 100644 --- a/sensors/queues_sensor.py +++ b/sensors/queues_sensor.py @@ -77,7 +77,10 @@ def setup(self): host=self.host, credentials=credentials, virtual_host=self.virtual_host ) else: - connection_params = pika.ConnectionParameters(host=self.host, virtual_host=self.virtual_host) + connection_params = pika.ConnectionParameters( + host=self.host, + virtual_host=self.virtual_host + ) self.conn = pika.BlockingConnection(connection_params) self.channel = self.conn.channel() From d77471c4768186896b87c2d10e5b0ebe98b7cc3f Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:42:59 +1100 Subject: [PATCH 5/6] chore: update CHANGES.md --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7be4d0c..b87be8f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # Change Log +# 1.1.2 +- Added virtual_host connection parameter to `queues_sensor` + # 1.1.1 - Updated pip dependency to pika `1.3.x` to support python >= 3.7 From f4c3597d438c39ff58cf120f9b32d9581ae77a30 Mon Sep 17 00:00:00 2001 From: Liam Best <4653939+0xliam@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:46:27 +1100 Subject: [PATCH 6/6] chore: update pack.yaml --- pack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack.yaml b/pack.yaml index 8882577..0471083 100644 --- a/pack.yaml +++ b/pack.yaml @@ -9,7 +9,7 @@ keywords: - aqmp - stomp - message broker -version: 1.1.1 +version: 1.1.2 python_versions: - "3" author: StackStorm, Inc.