Esempio n. 1
0
 async def _setup(self, context: Message):
     # Extract proxy info
     proxies = context.get('~proxy', [])
     channel_rpc = None
     channel_sub_protocol = None
     for proxy in proxies:
         if proxy['id'] == 'reverse':
             channel_rpc = proxy['data']['json']['address']
         elif proxy['id'] == 'sub-protocol':
             channel_sub_protocol = proxy['data']['json']['address']
     if channel_rpc is None:
         raise RuntimeError('rpc channel is empty')
     if channel_sub_protocol is None:
         raise RuntimeError('sub-protocol channel is empty')
     self.__tunnel_rpc = AddressedTunnel(address=channel_rpc,
                                         input_=self._connector,
                                         output_=self._connector,
                                         p2p=self._p2p)
     self.__tunnel_coprotocols = AddressedTunnel(
         address=channel_sub_protocol,
         input_=self._connector,
         output_=self._connector,
         p2p=self._p2p)
     # Extract active endpoints
     endpoints = context.get('~endpoints', [])
     endpoint_collection = []
     for endpoint in endpoints:
         body = endpoint['data']['json']
         address = body['address']
         frontend_key = body.get('frontend_routing_key', None)
         if frontend_key:
             for routing_key in body.get('routing_keys', []):
                 is_default = routing_key['is_default']
                 key = routing_key['routing_key']
                 endpoint_collection.append(
                     Endpoint(address=address,
                              routing_keys=[key, frontend_key],
                              is_default=is_default))
         else:
             endpoint_collection.append(
                 Endpoint(address=address,
                          routing_keys=[],
                          is_default=False))
     if not endpoint_collection:
         raise RuntimeError('Endpoints are empty')
     self.__endpoints = endpoint_collection
     # Extract Networks
     self.__networks = context.get('~networks', [])
 def __setup(self, message: Message, please_ack: bool = True):
     if please_ack:
         if PLEASE_ACK_DECORATOR not in message:
             message[PLEASE_ACK_DECORATOR] = {'message_id': message.id}
     if self.__thread_id:
         thread = message.get(THREAD_DECORATOR, {})
         if 'thid' not in thread:
             thread['thid'] = self.__thread_id
             message[THREAD_DECORATOR] = thread
Esempio n. 3
0
def build_response(packet: Message):
    if packet.get('@type') == MSG_TYPE_FUTURE:
        if packet.get('~thread', None) is not None:
            parsed = {'exception': None, 'value': None}
            exception = packet['exception']
            if exception:
                parsed['exception'] = exception
            else:
                value = packet['value']
                if packet['is_tuple']:
                    parsed['value'] = tuple(value)
                elif packet['is_bytes']:
                    parsed['value'] = base64.b64decode(value.encode('ascii'))
                else:
                    parsed['value'] = value
            return parsed
        else:
            raise SiriusInvalidPayloadStructure('Expect ~thread decorator')
    else:
        raise SiriusInvalidType('Expect message type "%s"' % MSG_TYPE_FUTURE)
Esempio n. 4
0
 async def _setup(self, context: Message):
     # Extract load balancing info
     balancing = context.get('~balancing', [])
     for balance in balancing:
         if balance['id'] == 'kafka':
             self.__balancing_group = balance['data']['json']['group_id']