utils
This module provides utility functions and classes for handling broker priorities and determining configurations for supported brokers such as RabbitMQ and Redis. It includes functionality for mapping priority levels to integer values based on the broker type and validating broker configurations.
Priority
Bases: Enum
Enumerated Priorities.
This enumeration defines the different priority levels that can be used for message handling with brokers.
Attributes:
| Name | Type | Description |
|---|---|---|
HIGH |
int
|
Represents the highest priority level. Numeric value: 1. |
MID |
int
|
Represents the medium priority level. Numeric value: 2. |
LOW |
int
|
Represents the lowest priority level. Numeric value: 3. |
RETRY |
int
|
Represents the priority level for retrying messages. Numeric value: 4. |
Source code in merlin/config/utils.py
determine_priority_map(broker_name)
Determine the priority mapping for the given broker name.
This function returns a mapping of Priority
enum values to integer priority levels based on the type of broker provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker for which to determine the priority map. |
required |
Returns:
| Type | Description |
|---|---|
Dict[Priority, int]
|
A dictionary mapping
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the broker name is not supported. |
Source code in merlin/config/utils.py
get_priority(priority)
Get the integer priority level for a given Priority
enum value.
This function determines the priority level as an integer based on the broker configuration. For RabbitMQ brokers, lower numbers represent lower priorities, while for Redis brokers, higher numbers represent lower priorities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
priority
|
Priority
|
The |
required |
Returns:
| Type | Description |
|---|---|
int
|
The integer priority level corresponding to the given |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided |
Source code in merlin/config/utils.py
is_rabbit_broker(broker_name)
Check if the given broker is a RabbitMQ server.
This function checks whether the provided broker name matches any of the RabbitMQ-related broker types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the broker is a RabbitMQ server, False otherwise. |
Source code in merlin/config/utils.py
is_redis_broker(broker_name)
Check if the given broker is a Redis server.
This function checks whether the provided broker name matches any of the Redis-related broker types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the broker is a Redis server, False otherwise. |
Source code in merlin/config/utils.py
resolve_password(password_value, server_type, certs_path=None)
Resolve a password configuration value into an actual password string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password_value
|
str
|
Either a direct password string or the name/path of a file containing the password. |
required |
server_type
|
str
|
The type of server (broker or results backend) for logging purposes. |
required |
certs_path
|
str
|
Optional directory for certificate/password files. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The resolved password (URL-quoted if not direct password). |