def __call__(self, fn: Callable): get_client().register_subscription_handler( subject=self.__subject, event=self.__event, handler_callback=fn, ) @wraps(fn) def wrapper(*args, **kwargs): return fn(*args, **kwargs) return wrapper
def __call__(self, fn: Callable): get_client().register_subscription_handler( subject=self.__subject, event_type=self.__event_type, handler_callback=fn, subscriber=str(fn.__qualname__).split(".")[0] ) @wraps(fn) def wrapper(*args, **kwargs): return fn(*args, **kwargs) return wrapper
async def _initializer(self, reactor: AsyncioSelectorReactor): reactor.listenTCP( self.__configuration.port(), ServiceFactory(configuration=self.__configuration, event_loop=asyncio.get_event_loop())) asyncio.get_event_loop().create_task(coro=get_client().start_up(), name="start-nats") reactor.run()
def __initialize(self, name: str, version: str) -> None: self.logger.info("Starting {0} VER: {1}".format(name, version)) self.reactor.listenTCP( self.__configuration.port(), ServiceFactory(configuration=self.__configuration, event_loop=self.__event_loop)) asyncio.set_event_loop(self.__event_loop) self.reactor.callLater(seconds=5, f=get_client().start_up) self.reactor.run()
def __send_direct_message_to_node(node: str, sender_identifier: str, target_identifier: str, payload: bytearray) -> None: client: ParticipantClient = get_client() passover: ParticipantPassOver = ParticipantPassOver( originating_node=node, sender_identifier=sender_identifier, target_identifier=target_identifier, payload=payload) client.passover_direct_message_to(passover=passover)
def __fetch_details(self, identifier: str) -> None: url: str = "{0}/{1}/{2}".format( self.__configuration.account_service_url(), "/api/v1/account-service/users/details", ) response: requests.Response = requests.get(url=url) if response.status_code is not 200: self._error("FAILED TO FETCH USER: {}".format(response.text)) else: content_map: Dict = response.json() if not self.is_identity_known( participant_identifier=content_map['identifier']): self.create_routing_identity( participant_identifier=content_map['identifier']) routing_identifier = self.fetch_routing_identity( participant_identifier=content_map['identifier']) self.__online_participants[identifier] = Participant( routing_identity=routing_identifier, content_map=response.json()) self.__route_pairing[routing_identifier] = content_map['identity'] self.__contact_pairing[response.json()["email"]] = identifier self._info("ADDED PARTICIPANT ENTRY FOR: {}".format(identifier)) get_client().register_participant( routing_identifier=routing_identifier)
def __resolve_last_known_node(target_identifier: str) -> Optional[str]: client: ParticipantClient = get_client() return client.fetch_last_known_node( target_identifier=target_identifier)
def initialize_services(self) -> None: self.__participant_service = ParticipantService(configuration=self.__configuration, command_bus=self.__command_bus, participant_repository=self.__participant_repository, message_repository=self.__message_repository) get_client().register_subscriber(subscriber=self.__participant_service)
def stopFactory(self): self.__database_provider.close() get_client().shutdown()