Skip to content

Commit 88ae4fb

Browse files
committed
virtual host retrieval explicit
1 parent 7f7bf93 commit 88ae4fb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

rabbitmq_amqp_python_client/qpid/proton/_reactor.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
Type,
3636
Union,
3737
)
38+
from urllib.parse import urlparse
3839

3940
try:
4041
from typing import Literal
@@ -1038,7 +1039,7 @@ def __iter__(self) -> Iterator[float]:
10381039

10391040

10401041
def make_backoff_wrapper(
1041-
backoff: Optional[Union[List[Union[float, int]], bool, Backoff]]
1042+
backoff: Optional[Union[List[Union[float, int]], bool, Backoff]],
10421043
) -> Optional[Union[List[Union[float, int]], bool, Backoff]]:
10431044
"""
10441045
Make a wrapper for a backoff object:
@@ -1099,7 +1100,7 @@ def _connect(self, connection: Connection, url: Url) -> None:
10991100
connection.url = url
11001101
# if virtual-host not set, use host from address as default
11011102
if self.virtual_host is None:
1102-
connection.hostname = url.host
1103+
connection.hostname = url.path
11031104
_logger.info("Connecting to %r..." % url)
11041105

11051106
transport = Transport()
@@ -1291,7 +1292,7 @@ def connect(
12911292
reconnect: Union[None, Literal[False], Backoff] = None,
12921293
heartbeat: Optional[float] = None,
12931294
ssl_domain: Optional[SSLDomain] = None,
1294-
**kwargs
1295+
**kwargs,
12951296
) -> Connection:
12961297
"""
12971298
Initiates the establishment of an AMQP connection.
@@ -1427,7 +1428,7 @@ def connect(
14271428
reconnect=reconnect,
14281429
heartbeat=heartbeat,
14291430
ssl_domain=_ssl_domain,
1430-
**_kwargs
1431+
**_kwargs,
14311432
)
14321433
else:
14331434
return self._connect(
@@ -1437,7 +1438,7 @@ def connect(
14371438
reconnect=reconnect,
14381439
heartbeat=heartbeat,
14391440
ssl_domain=ssl_domain,
1440-
**kwargs
1441+
**kwargs,
14411442
)
14421443

14431444
def _connect(
@@ -1448,7 +1449,7 @@ def _connect(
14481449
reconnect: Optional[Union[List[Union[float, int]], bool, Backoff]] = None,
14491450
heartbeat: None = None,
14501451
ssl_domain: Optional[SSLDomain] = None,
1451-
**kwargs
1452+
**kwargs,
14521453
) -> Connection:
14531454
conn = self.connection(handler)
14541455
conn.container = kwargs.get("container_id", self.container_id) or str(
@@ -1467,6 +1468,14 @@ def _connect(
14671468
connector.user = kwargs.get("user", self.user)
14681469
connector.password = kwargs.get("password", self.password)
14691470
connector.virtual_host = kwargs.get("virtual_host")
1471+
if not connector.virtual_host and isinstance(url, Url):
1472+
connector.virtual_host = url.path
1473+
elif not connector.virtual_host and urls and isinstance(urls[0], Url):
1474+
connector.virtual_host = urls[0].path
1475+
elif not connector.virtual_host and isinstance(url, str):
1476+
connector.virtual_host = urlparse(url).path
1477+
elif not connector.virtual_host and urls and isinstance(urls[0], str):
1478+
connector.virtual_host = urlparse(urls[0]).path
14701479
if connector.virtual_host:
14711480
# only set hostname if virtual-host is a non-empty string
14721481
conn.hostname = connector.virtual_host

0 commit comments

Comments
 (0)