Skip to content

Commit 41a7ecc

Browse files
committed
- Updated to new Builder.
- Renamed attributes broker_* to *. issue #283
1 parent dd694cb commit 41a7ecc

File tree

3 files changed

+52
-13
lines changed

3 files changed

+52
-13
lines changed

packages/plugins/minos-broker-rabbitmq/minos/plugins/rabbitmq/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
__email__ = "[email protected]"
33
__version__ = "0.5.1"
44

5+
from .common import (
6+
RabbitMQBrokerBuilderMixin
7+
)
58
from .publisher import (
69
InMemoryQueuedRabbitMQBrokerPublisher,
710
PostgreSqlQueuedRabbitMQBrokerPublisher,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import (
2+
annotations,
3+
)
4+
5+
from minos.common import (
6+
Builder,
7+
Config,
8+
)
9+
10+
11+
class RabbitMQBrokerBuilderMixin(Builder):
12+
"""RabbitMQ Broker Builder Mixin class."""
13+
14+
def with_config(self, config: Config):
15+
"""Set config.
16+
17+
:param config: The config to be set.
18+
:return: This method return the builder instance.
19+
"""
20+
broker_config = config.get_interface_by_name("broker")
21+
common_config = broker_config.get("common", dict())
22+
23+
self.kwargs |= {
24+
"group_id": config.get_name(),
25+
"host": common_config.get("host"),
26+
"port": common_config.get("port"),
27+
}
28+
return super().with_config(config)

packages/plugins/minos-broker-rabbitmq/minos/plugins/rabbitmq/publisher.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
BrokerPublisher,
1818
InMemoryBrokerPublisherQueue,
1919
PostgreSqlBrokerPublisherQueue,
20-
QueuedBrokerPublisher,
20+
QueuedBrokerPublisher, BrokerPublisherBuilder,
2121
)
22+
from minos.plugins.rabbitmq.common import RabbitMQBrokerBuilderMixin
2223

2324
logger = logging.getLogger(__name__)
2425

@@ -46,19 +47,19 @@ def _from_config(cls, config: MinosConfig, **kwargs) -> InMemoryQueuedRabbitMQBr
4647
class RabbitMQBrokerPublisher(BrokerPublisher):
4748
"""RabbitMQ Broker Publisher class."""
4849

49-
def __init__(self, *args, broker_host: str, broker_port: int, **kwargs):
50+
def __init__(self, *args, host: str, port: int, **kwargs):
5051
super().__init__(*args, **kwargs)
51-
self.broker_host = broker_host
52-
self.broker_port = broker_port
53-
54-
@classmethod
55-
def _from_config(cls, config: MinosConfig, **kwargs) -> RabbitMQBrokerPublisher:
56-
broker_config = config.get_interface_by_name("broker")
57-
common_config = broker_config["common"]
58-
59-
kwargs["broker_host"] = common_config["host"]
60-
kwargs["broker_port"] = common_config["port"]
61-
return cls(**kwargs)
52+
self.broker_host = host
53+
self.broker_port = port
54+
55+
# @classmethod
56+
# def _from_config(cls, config: MinosConfig, **kwargs) -> RabbitMQBrokerPublisher:
57+
# broker_config = config.get_interface_by_name("broker")
58+
# common_config = broker_config["common"]
59+
#
60+
# kwargs["broker_host"] = common_config["host"]
61+
# kwargs["broker_port"] = common_config["port"]
62+
# return cls(**kwargs)
6263

6364
async def _setup(self) -> None:
6465
await super()._setup()
@@ -72,3 +73,10 @@ async def _send(self, message: BrokerMessage) -> None:
7273
channel = await self.connection.channel()
7374
queue = await channel.declare_queue(message.topic)
7475
await channel.default_exchange.publish(Message(message.avro_bytes), routing_key=queue.name)
76+
77+
78+
class RabbitMQBrokerPublisherBuilder(BrokerPublisherBuilder[RabbitMQBrokerPublisher], RabbitMQBrokerBuilderMixin):
79+
"""RabbitMQ Broker Publisher Builder class."""
80+
81+
82+
RabbitMQBrokerPublisher.set_builder(RabbitMQBrokerPublisherBuilder)

0 commit comments

Comments
 (0)