def open(self, consumer_name: str) -> None: # TODO: Build then refactor with receive # Find the consumer if consumer_name not in self._consumers: raise ConfigurationException( "The consumer {} could not be found, did you register it?". format(consumer_name)) consumer = self._consumers[consumer_name] performer = Performer(consumer_name, consumer.connection, consumer.brightside_configuration, consumer.consumer_factory, consumer.command_processor_factory, consumer.mapper_func) self._performers[consumer_name] = performer # if we have a supervisor thread if self._state == DispatcherState.ds_running: # start and add to items monitored by supervisor (running performers) pass # else elif self._state == DispatcherState.ds_stopped: # start the supervisor with the single consumer self._state = DispatcherState.ds_awaiting self.receive() else: raise MessagingException( "Dispatcher in a un-recognised state to open new connection; state was {}", self._state)
def _add_message_type(brightside_message_header: Dict, brightside_message_type: str) -> None: if brightside_message_type is None: raise MessagingException( "Missing type on message, this is a required field") brightside_message_header[ message_type_header] = brightside_message_type
def __init__(self, request: Request = None, serialized_request: str = None): if request is None and serialized_request is None: raise MessagingException( "You must provide either an object to serialize, or a dictionary of object properties and an object to hydrate" ) self._request = request self._serialized_request = serialized_request
def serialize_to_json(self): def _serialize_instance(obj: object) -> Dict: d = {} d.update(vars(obj)) for key, value in d.items(): if isinstance( value, UUID ): # json does not know how to serliaze a UUID, so convince it is a string instead d[key] = str(value) return d if self._request is None: raise MessagingException("You must provide a request to serialize") return json.dumps(self._request, default=_serialize_instance)
def _add_message_id(brightside_message_header: Dict, identity: UUID) -> None: if identity is None: raise MessagingException( "Missing id on message, this is a required field") brightside_message_header[message_id_header] = str(identity)