Skip to content

[Draft] Add vhost support #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions rabbitmq_amqp_python_client/qpid/proton/_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Type,
Union,
)
from urllib.parse import urlparse

try:
from typing import Literal
Expand Down Expand Up @@ -1038,7 +1039,7 @@ def __iter__(self) -> Iterator[float]:


def make_backoff_wrapper(
backoff: Optional[Union[List[Union[float, int]], bool, Backoff]]
backoff: Optional[Union[List[Union[float, int]], bool, Backoff]],
) -> Optional[Union[List[Union[float, int]], bool, Backoff]]:
"""
Make a wrapper for a backoff object:
Expand Down Expand Up @@ -1099,7 +1100,7 @@ def _connect(self, connection: Connection, url: Url) -> None:
connection.url = url
# if virtual-host not set, use host from address as default
if self.virtual_host is None:
connection.hostname = url.host
connection.hostname = url.path
_logger.info("Connecting to %r..." % url)

transport = Transport()
Expand Down Expand Up @@ -1291,7 +1292,7 @@ def connect(
reconnect: Union[None, Literal[False], Backoff] = None,
heartbeat: Optional[float] = None,
ssl_domain: Optional[SSLDomain] = None,
**kwargs
**kwargs,
) -> Connection:
"""
Initiates the establishment of an AMQP connection.
Expand Down Expand Up @@ -1427,7 +1428,7 @@ def connect(
reconnect=reconnect,
heartbeat=heartbeat,
ssl_domain=_ssl_domain,
**_kwargs
**_kwargs,
)
else:
return self._connect(
Expand All @@ -1437,7 +1438,7 @@ def connect(
reconnect=reconnect,
heartbeat=heartbeat,
ssl_domain=ssl_domain,
**kwargs
**kwargs,
)

def _connect(
Expand All @@ -1448,7 +1449,7 @@ def _connect(
reconnect: Optional[Union[List[Union[float, int]], bool, Backoff]] = None,
heartbeat: None = None,
ssl_domain: Optional[SSLDomain] = None,
**kwargs
**kwargs,
) -> Connection:
conn = self.connection(handler)
conn.container = kwargs.get("container_id", self.container_id) or str(
Expand All @@ -1467,6 +1468,14 @@ def _connect(
connector.user = kwargs.get("user", self.user)
connector.password = kwargs.get("password", self.password)
connector.virtual_host = kwargs.get("virtual_host")
if not connector.virtual_host and isinstance(url, Url):
connector.virtual_host = url.path
elif not connector.virtual_host and urls and isinstance(urls[0], Url):
connector.virtual_host = urls[0].path
elif not connector.virtual_host and isinstance(url, str):
connector.virtual_host = urlparse(url).path
elif not connector.virtual_host and urls and isinstance(urls[0], str):
connector.virtual_host = urlparse(urls[0]).path
if connector.virtual_host:
# only set hostname if virtual-host is a non-empty string
conn.hostname = connector.virtual_host
Expand Down
Loading