Fix the global unique ID generator recursive constructor call
This commit is contained in:
@@ -10,6 +10,7 @@ from aio_pika.abc import AbstractRobustExchange
|
||||
|
||||
from amqp.adapter.amq_route_factory import AMQRouteFactory
|
||||
from amqp.adapter.backpressure_handler import BackpressureHandler
|
||||
from amqp.adapter.consul_global_id_generator import get_unique_instance_id
|
||||
from amqp.adapter.data_message_factory import DataMessageFactory
|
||||
from amqp.adapter.logging_utils import logging_info, logging_warning
|
||||
from amqp.adapter.service_message_factory import ServiceMessageFactory
|
||||
@@ -37,14 +38,17 @@ class AMQService:
|
||||
|
||||
def __init__(self, amq_configuration: AMQConfiguration, service_adapter=None):
|
||||
logging.info("***********************************************")
|
||||
logging.info("********** AMQ Service *******************")
|
||||
logging.info("************** AMQ Service ***************")
|
||||
logging.info("***********************************************")
|
||||
self.loop = asyncio.new_event_loop()
|
||||
|
||||
self.amq_configuration = amq_configuration
|
||||
self.service_adapter = service_adapter
|
||||
self.unique_id = get_unique_instance_id(amq_configuration.amq_adapter)
|
||||
amq_configuration.amq_adapter.generator_id = self.unique_id
|
||||
|
||||
self.data_message_factory = DataMessageFactory.get_instance(
|
||||
self.amq_configuration.amq_adapter.generator_id
|
||||
self.unique_id & DataMessageFactory.MACHINE_ID_MASK
|
||||
)
|
||||
self.router = RouterConsumer(self.amq_configuration)
|
||||
self.rabbit_mq_client = RabbitMQClient(self.amq_configuration, self.router)
|
||||
@@ -63,7 +67,7 @@ class AMQService:
|
||||
|
||||
# =======================================================================
|
||||
# =======================================================================
|
||||
# ====================== A P I M e t h o d s =========================
|
||||
# ============== P u b l i c A P I M e t h o d s ===================
|
||||
# =======================================================================
|
||||
# =======================================================================
|
||||
def run(self):
|
||||
@@ -123,6 +127,15 @@ class AMQService:
|
||||
)
|
||||
return result
|
||||
|
||||
def get_unique_instance_id(self) -> int:
|
||||
"""
|
||||
Provides cluster-wide unique instance ID for this AMQ service instance.
|
||||
This ID is used to identify the service instance in the cluster and is unique across all instances.
|
||||
IDs are managed by shared Consul KV store, ensuring that even if multiple instances of the service are running,
|
||||
they will each have unique ID.
|
||||
"""
|
||||
return self.unique_id
|
||||
|
||||
# =======================================================================
|
||||
# ====================== Internal Methods ============================
|
||||
# =======================================================================
|
||||
|
||||
Reference in New Issue
Block a user