def add_message(event_type, payload, session=None): """ Add a message to be submitted asynchronously to a message broker. In the case of nolimit, a placeholder string is written to the NOT NULL payload column. :param event_type: The type of the event as a string, e.g., NEW_DID. :param payload: The message payload. Will be persisted as JSON. :param session: The database session to use. """ services_list = REGION.get('services_list') if services_list == NO_VALUE: try: services_list = get('hermes', 'services_list') except ConfigNotFound: services_list = None REGION.set('services_list', services_list) try: payload = json.dumps(payload, cls=APIEncoder) except TypeError as e: raise InvalidObject('Invalid JSON for payload: %(e)s' % locals()) if len(payload) > 4000: new_message = Message(event_type=event_type, payload='nolimit', payload_nolimit=payload, services=services_list) else: new_message = Message(event_type=event_type, payload=payload, services=services_list) new_message.save(session=session, flush=False)
def add_message(event_type, payload, session=None): """ Add a message to be submitted asynchronously to a message broker. :param event_type: The type of the event as a string, e.g., NEW_DID. :param payload: The message payload. Will be persisted as JSON. :param session: The database session to use. """ try: new_message = Message(event_type=event_type, payload=json.dumps(payload)) except TypeError, e: raise InvalidObject('Invalid JSON for payload: %(e)s' % locals())
def add_message(event_type, payload, session=None): """ Add a message to be submitted asynchronously to a message broker. In the case of nolimit, a placeholder string is written to the NOT NULL payload column. :param event_type: The type of the event as a string, e.g., NEW_DID. :param payload: The message payload. Will be persisted as JSON. :param session: The database session to use. """ try: payload = json.dumps(payload) except TypeError as e: raise InvalidObject('Invalid JSON for payload: %(e)s' % locals()) if len(payload) > 4000: new_message = Message(event_type=event_type, payload='nolimit', payload_nolimit=payload) else: new_message = Message(event_type=event_type, payload=payload) new_message.save(session=session, flush=False)