Skip to content

Commit 491890b

Browse files
authored
Merge pull request #8057 from nakshathru/main
Added authentication support for AQMP broker url
2 parents 954107f + 0b63659 commit 491890b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

changelog/8057.improvement.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added authentication support for connecting to external RabbitMQ servers.
2+
Currently user has to hardcode a username and a password in a URL in order to connect to an external RabbitMQ server.

rasa/core/brokers/pika.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from asyncio import AbstractEventLoop
77
from collections import deque
88
from typing import Deque, Dict, Optional, Text, Union, Any, List, Tuple
9+
from urllib.parse import urlparse
910

1011
import aio_pika
1112

@@ -168,7 +169,10 @@ async def _connect(self) -> aio_pika.RobustConnection:
168169
# The `url` parameter will take precedence over parameters like `login` or
169170
# `password`.
170171
if self.host.startswith("amqp"):
171-
url = self.host
172+
173+
parsed_host = urlparse(self.host)
174+
amqp_user = f"{self.username}:{self.password}"
175+
url = f"{parsed_host.scheme}://{amqp_user}@{parsed_host.netloc}:{self.port}"
172176

173177
ssl_options = _create_rabbitmq_ssl_options(self.host)
174178
logger.info("Connecting to RabbitMQ ...")

0 commit comments

Comments
 (0)