|
1 | 1 | """Binding resolution with comprehensive pattern matching""" |
2 | 2 |
|
3 | 3 | from typing import Any |
4 | | -from asyncapi_python.kernel.wire import EndpointParams |
5 | | -from asyncapi_python.kernel.document.channel import Channel |
| 4 | + |
6 | 5 | from asyncapi_python.kernel.document.bindings import AmqpChannelBinding |
| 6 | +from asyncapi_python.kernel.document.channel import Channel |
| 7 | +from asyncapi_python.kernel.wire import EndpointParams |
7 | 8 |
|
8 | | -from .config import AmqpConfig, AmqpBindingType |
9 | | -from .utils import validate_parameters_strict, substitute_parameters |
| 9 | +from .config import AmqpBindingType, AmqpConfig |
| 10 | +from .utils import substitute_parameters, validate_parameters_strict |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def resolve_amqp_config( |
@@ -57,17 +58,32 @@ def resolve_amqp_config( |
57 | 58 | }, |
58 | 59 | ) |
59 | 60 |
|
60 | | - # Reply channel with explicit address - shared channel with filtering |
| 61 | + # Reply channel with explicit address - check if direct queue or topic exchange |
61 | 62 | case (True, _, address, _) if address: |
62 | 63 | resolved_address = substitute_parameters(address, param_values) |
63 | | - return AmqpConfig( |
64 | | - queue_name=f"reply-{app_id}", # App-specific reply queue |
65 | | - exchange_name=resolved_address, # Shared exchange for replies |
66 | | - exchange_type="topic", # Enable pattern matching for filtering |
67 | | - routing_key=app_id, # Filter messages by app_id |
68 | | - binding_type=AmqpBindingType.REPLY, |
69 | | - queue_properties={"durable": True, "exclusive": False}, |
70 | | - ) |
| 64 | + # If address starts with "reply-", treat it as a direct queue name (RPC pattern) |
| 65 | + if resolved_address.startswith("reply-"): |
| 66 | + return AmqpConfig( |
| 67 | + queue_name=resolved_address, # Use address as queue name |
| 68 | + exchange_name="", # Default exchange for direct routing |
| 69 | + routing_key=resolved_address, # Route directly to queue |
| 70 | + binding_type=AmqpBindingType.REPLY, |
| 71 | + queue_properties={ |
| 72 | + "durable": False, |
| 73 | + "exclusive": True, |
| 74 | + "auto_delete": True, |
| 75 | + }, |
| 76 | + ) |
| 77 | + else: |
| 78 | + # Topic-based reply pattern - shared exchange with filtering |
| 79 | + return AmqpConfig( |
| 80 | + queue_name=f"reply-{app_id}", # App-specific reply queue |
| 81 | + exchange_name=resolved_address, # Shared exchange for replies |
| 82 | + exchange_type="topic", # Enable pattern matching for filtering |
| 83 | + routing_key=app_id, # Filter messages by app_id |
| 84 | + binding_type=AmqpBindingType.REPLY, |
| 85 | + queue_properties={"durable": True, "exclusive": False}, |
| 86 | + ) |
71 | 87 |
|
72 | 88 | # Reply channel with binding - defer to binding resolution |
73 | 89 | case (True, binding, _, _) if binding and binding.type == "queue": |
|
0 commit comments