Router Module
- class amqp.router.router_base.RouterBase[source]
Bases:
object- get_routing_key(message)[source]
- Parameters:
message (DataMessage)
- Return type:
str
- find_route_by_message(message)[source]
- Parameters:
message (DataMessage)
- Return type:
AMQRoute | None
- class amqp.router.router_consumer.RouterConsumer(configuration)[source]
Bases:
RouterProducerContains Consumer logic. The logic here:
Sets a listener on CM_C_REQ_QUEUE queue to receive routing data requests
Upon receipt of routing data request, responds on CM_RESPONSE_EXCHANGE with local routing data.
It also proactively pushes the local routing data to CM_RESPONSE_EXCHANGE on startup to
notify the other (excluding self) Producers about its presence.
Consumer is also Producer (Consumer sits alongside the CM Service, and anytime the Service needs
to communicate with other Service, it can do so via the Adapter). Therefore, the Producer
capability is also required.
- Parameters:
configuration (AMQConfiguration)
- __init__(configuration)[source]
Initialize router - need to supply the config values and RabbitMQ channel.
- param configuration:
adapter’s configuration reference.
- Parameters:
configuration (AMQConfiguration)
- async init_routing_paths_consumer(_channel)[source]
Initialize router according to Consumer mode.
- Parameters:
_channel (AbstractRobustChannel)
- async handle_routing_data_request_message(message)[source]
- Parameters:
message (AbstractIncomingMessage)
- async register_route(route)[source]
Called in Consumer (Service Adapter) context. Registers the routing data for self Service
with the Master router by sending own routing data to Master via CleverMicroResponse queue.
- param route:
route to register with Master
- Parameters:
route (AMQRoute)
Maps the request to RabbitMQ exchange. Handles the service discovery logic.
Router can be either in ‘Master’ or ‘Service (Consumer)’ modes. ‘Master’ mode is the outward
facing side that receives the requests and routes it to queue associated with requested service.
‘Service’ mode is consumer side for given service, which receives the message from AMQ and
forwards it to the application.
- class amqp.router.router_producer.RouterProducer(configuration)[source]
Bases:
RouterBase- Parameters:
configuration (AMQConfiguration)
- __init__(configuration)[source]
Initialize router - need to supply the config values and RabbitMQ channel.
- param configuration:
adapter’s configuration reference.
- Parameters:
configuration (AMQConfiguration)
- async init_internal_routing_paths(channel)[source]
Initialize internal routes for ServiceMessages.
The logic here sets a producer and listener on CleverMicroRequest/CleverMicroResponse queues
created to enable the service discovery.
The Producer mode sends out routing data request on CleverMicroRequest and listens
on CleverMicroResponse for any service responding with its routing data.
- Parameters:
channel (AbstractRobustChannel | None)
- async handle_routing_data_message(message)[source]
Handler for CLEVER_MICRO_RESPONSE queue messages. Used in Master mode to handle receipt of
routing data, invokes addRoute or removeRoute depending on the type of the message.
- Parameters:
message (AbstractIncomingMessage)
- async request_routes_from_adapters()[source]
Send a broadcast message prompting all listening adapters to reply with own routing data.
- async publish_service_message(message, exchange)[source]
Publishes a service message to the service queue and logs success log entry.
- param message:
Service Message to be sent
- param exchange:
target exchange name where to publish the message
:return True if channel is open, False otherwise
@throws IOException if something else goes wrong
- Parameters:
message (ServiceMessage)
exchange (AbstractRobustExchange)
- Return type:
bool
- get_reply_to_queue_name()[source]
self should create a unique name for self process and also when there’s several instances.
@return unique reply-to queue name.
- Return type:
str
- get_response_queue_name()[source]
self should create a unique name for self process and also when there’s several instances.
@return unique reply-to queue name.
- Return type:
str
- class amqp.router.route_database.RouteDatabase[source]
Bases:
object- matches(routing_key_from_route, routing_key_from_message)[source]
- Parameters:
routing_key_from_route (str)
routing_key_from_message (str)
- Return type:
bool
- amqp.router.utils.sanitize_as_rabbitmq_name(input_str)[source]
- Parameters:
input_str (str)
- Return type:
str
- amqp.router.utils.sanitize_as_rabbitmq_domain_name(token)[source]
- Parameters:
token (str)
- Return type:
str