Skip to content

Commit 319e22b

Browse files
author
DanielePalaia
committed
adding a class for CustomExchangeSpec
1 parent ee0e5dd commit 319e22b

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

rabbitmq_amqp_python_client/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .connection import Connection
77
from .consumer import Consumer
88
from .entities import (
9+
ExchangeCustomSpecification,
910
ExchangeSpecification,
1011
ExchangeToExchangeBindingSpecification,
1112
ExchangeToQueueBindingSpecification,
@@ -75,4 +76,5 @@
7576
"OffsetSpecification",
7677
"OutcomeState",
7778
"Environment",
79+
"ExchangeCustomSpecification",
7880
]

rabbitmq_amqp_python_client/entities.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@
1414
class ExchangeSpecification:
1515
name: str
1616
arguments: dict[str, str] = field(default_factory=dict)
17-
exchange_type: Union[ExchangeType, str] = ExchangeType.direct
17+
exchange_type: ExchangeType = ExchangeType.direct
18+
is_auto_delete: bool = False
19+
is_internal: bool = False
20+
is_durable: bool = True
21+
22+
23+
@dataclass
24+
class ExchangeCustomSpecification:
25+
name: str
26+
exchange_type: str
27+
arguments: dict[str, str] = field(default_factory=dict)
1828
is_auto_delete: bool = False
1929
is_internal: bool = False
2030
is_durable: bool = True

rabbitmq_amqp_python_client/management.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
from typing import Any, Optional, Union
44

55
from .address_helper import AddressHelper
6-
from .common import CommonValues, ExchangeType, QueueType
6+
from .common import CommonValues, QueueType
77
from .entities import (
8+
ExchangeCustomSpecification,
89
ExchangeSpecification,
910
ExchangeToExchangeBindingSpecification,
1011
ExchangeToQueueBindingSpecification,
@@ -98,16 +99,19 @@ def _request(
9899
return msg
99100

100101
def declare_exchange(
101-
self, exchange_specification: ExchangeSpecification
102-
) -> ExchangeSpecification:
102+
self,
103+
exchange_specification: Union[
104+
ExchangeSpecification, ExchangeCustomSpecification
105+
],
106+
) -> Union[ExchangeSpecification, ExchangeCustomSpecification]:
103107
logger.debug("declare_exchange operation called")
104108
body: dict[str, Any] = {}
105109
body["auto_delete"] = exchange_specification.is_auto_delete
106110
body["durable"] = exchange_specification.is_durable
107-
if isinstance(exchange_specification.exchange_type, ExchangeType):
111+
if isinstance(exchange_specification, ExchangeSpecification):
108112
body["type"] = exchange_specification.exchange_type.value
109-
else:
110-
body["type"] = str(exchange_specification.exchange_type)
113+
elif isinstance(exchange_specification, ExchangeCustomSpecification):
114+
body["type"] = exchange_specification.exchange_type
111115
body["internal"] = exchange_specification.is_internal
112116
body["arguments"] = exchange_specification.arguments
113117

tests/test_management.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from rabbitmq_amqp_python_client import (
44
ClassicQueueSpecification,
5+
ExchangeCustomSpecification,
56
ExchangeSpecification,
67
ExchangeToExchangeBindingSpecification,
78
ExchangeToQueueBindingSpecification,
@@ -50,9 +51,9 @@ def test_declare_delete_exchange_custom(management: Management) -> None:
5051
exchange_arguments["x-delayed-type"] = "direct"
5152

5253
exchange_info = management.declare_exchange(
53-
ExchangeSpecification(
54+
ExchangeCustomSpecification(
5455
name=exchange_name,
55-
exchange_type="x-local-random",
56+
exchange_type="direct",
5657
arguments=exchange_arguments,
5758
)
5859
)

0 commit comments

Comments
 (0)