Skip to content

Commit 92afe13

Browse files
committed
fixing vhost, username, password for protocol adapter and clients
1 parent eea1e37 commit 92afe13

17 files changed

+157
-28
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ simulation_bridge:
155155
rabbitmq:
156156
host: localhost # RabbitMQ server hostname or IP
157157
port: 5672 # RabbitMQ port (default is 5672)
158-
virtual_host: / # RabbitMQ virtual host to use
159-
158+
vhost: / # RabbitMQ virtual host to use
159+
username: guest # Username
160+
password: guest # Password
160161
infrastructure:
161162
exchanges:
162163
# Define all the exchanges used by the bridge
@@ -214,20 +215,16 @@ mqtt:
214215
input_topic: bridge/input # Topic to subscribe to for input
215216
output_topic: bridge/output # Topic to publish results
216217
qos: 0 # Quality of Service level (0: at most once)
218+
username: guest # Username
219+
password: guest # Password
217220

218221
# Configuration for REST protocol adapter
219222
rest:
220223
host: 0.0.0.0 # Host IP to bind the REST server (0.0.0.0 = all interfaces)
221224
port: 5000 # Port to run the REST server
222-
input_endpoint: /message # Endpoint for receiving messages
225+
endpoint: /message # Endpoint for receiving messages
223226
debug: false # Enable/disable Flask debug mode
224227

225-
client:
226-
host: localhost # REST client target host
227-
port: 5001 # Port of the external REST receiver
228-
base_url: http://localhost:5001 # Base URL for outgoing REST requests
229-
output_endpoint: /result # Path for sending result messages
230-
231228
# Logging configuration
232229
logging:
233230
level: INFO # Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
@@ -292,7 +289,7 @@ The developer-specific commands are
292289
```bash
293290
pylint simulation_bridge
294291
autopep8 --in-place --aggressive --recursive 'simulation_bridge'
295-
pytest --cov=simulation_bridge --cov-report=term --cov-report=html simulation_bridge/test/unit/
292+
pytest --cov=simulation_bridge --cov-report=term --cov-report=html simulation_bridge/test/
296293
open htmlcov/index.html
297294
```
298295

poetry.lock

Lines changed: 102 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mypy = "^1.15.0"
3939
pytest = "^8.3.5"
4040
pytest-asyncio = "^1.0.0"
4141
types-pyyaml = "^6.0.12.20250402"
42+
pytest-cov = "^6.1.1"
4243

4344
[build-system]
4445
requires = ["poetry-core>=2.0.0,<3.0.0"]

simulation_bridge/config/config.yaml.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ simulation_bridge:
44
rabbitmq:
55
host: localhost
66
port: 5672
7-
virtual_host: /
7+
vhost: /
88
username: guest
99
password: guest
10+
1011
infrastructure:
1112
exchanges:
1213
- name: ex.input.bridge

simulation_bridge/resources/mqtt/mqtt_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self, config):
4242
self.config = config['mqtt']
4343
self.payload_file = config.get('payload_file', 'simulation.yaml')
4444
self.client = mqtt.Client()
45+
self.client.username_pw_set(
46+
self.config['username'],
47+
self.config['password']
48+
)
4549
self.client.on_message = self.on_message
4650

4751
def on_message(self, client, userdata, msg): # pylint: disable=unused-argument

simulation_bridge/resources/rabbitmq/rabbitmq_client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@ def __init__(self, config):
2828
"""Initialize the Digital Twin with the given configuration."""
2929
self.config = config
3030
self.dt_id = config['digital_twin']['dt_id']
31-
self.connection = pika.BlockingConnection(
32-
pika.ConnectionParameters(config['rabbitmq_host'])
31+
32+
rabbitmq_cfg = config['rabbitmq']
33+
credentials = pika.PlainCredentials(
34+
username=rabbitmq_cfg['username'],
35+
password=rabbitmq_cfg['password']
36+
)
37+
parameters = pika.ConnectionParameters(
38+
host=rabbitmq_cfg['host'],
39+
port=rabbitmq_cfg.get('port', 5672),
40+
virtual_host=rabbitmq_cfg.get('vhost', '/'),
41+
credentials=credentials
3342
)
43+
44+
self.connection = pika.BlockingConnection(parameters)
3445
self.channel = self.connection.channel()
3546
self.result_queue_name = None
3647
self.setup_infrastructure()

simulation_bridge/src/core/bridge_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _initialize_rabbitmq_connection(self):
7777
pika.ConnectionParameters(
7878
host=self.config['host'],
7979
port=self.config['port'],
80-
virtual_host=self.config['virtual_host'],
80+
virtual_host=self.config['vhost'],
8181
credentials=credentials,
8282
heartbeat=RABBITMQ_HEARTBEAT,
8383
blocked_connection_timeout=RABBITMQ_BLOCKED_CONNECTION_TIMEOUT,

simulation_bridge/src/core/bridge_infrastructure.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, config_manager: ConfigManager):
3030
pika.ConnectionParameters(
3131
host=self.config['host'],
3232
port=self.config['port'],
33-
virtual_host=self.config['virtual_host'],
33+
virtual_host=self.config['vhost'],
3434
credentials=credentials
3535
)
3636
)
@@ -52,12 +52,18 @@ def setup(self):
5252

5353
def reconnect(self):
5454
"""Reconnect to RabbitMQ if connection was closed."""
55+
5556
if self.connection.is_closed:
57+
credentials = pika.PlainCredentials(
58+
self.config['username'],
59+
self.config['password']
60+
)
5661
self.connection = pika.BlockingConnection(
5762
pika.ConnectionParameters(
5863
host=self.config['host'],
5964
port=self.config['port'],
60-
virtual_host=self.config['virtual_host']
65+
virtual_host=self.config['vhost'],
66+
credentials=credentials
6167
)
6268
)
6369
self.channel = self.connection.channel()

simulation_bridge/src/protocol_adapters/rabbitmq/rabbitmq_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, config_manager: ConfigManager):
4646
pika.ConnectionParameters(
4747
host=self.config['host'],
4848
port=self.config['port'],
49-
virtual_host=self.config['virtual_host'],
49+
virtual_host=self.config['vhost'],
5050
credentials=credentials
5151
)
5252
)

simulation_bridge/src/utils/config_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class RabbitMQConfig(BaseModel):
5959
"""Configuration for RabbitMQ connection."""
6060
host: str
6161
port: int
62-
virtual_host: str
62+
vhost: str
6363
username: str
6464
password: str
6565
infrastructure: RabbitMQInfrastructure
@@ -146,7 +146,7 @@ def from_dict(cls, config_dict: Dict[str, Any]) -> 'Config':
146146
rabbit_config = RabbitMQConfig(
147147
host=rabbitmq_dict.get('host', 'localhost'),
148148
port=rabbitmq_dict.get('port', 5672),
149-
virtual_host=rabbitmq_dict.get('virtual_host', '/'),
149+
vhost=rabbitmq_dict.get('vhost', '/'),
150150
username=rabbitmq_dict.get('username', 'guest'),
151151
password=rabbitmq_dict.get('password', 'guest'),
152152
infrastructure=infrastructure
@@ -217,7 +217,7 @@ def get_default_config(self) -> Dict[str, Any]:
217217
rabbitmq=RabbitMQConfig(
218218
host="localhost",
219219
port=5672,
220-
virtual_host="/",
220+
vhost="/",
221221
username="guest",
222222
password="guest",
223223
infrastructure=RabbitMQInfrastructure(

0 commit comments

Comments
 (0)