Exemple #1
0
    def send_request(self, service, subject, body, headers=None):
        if isinstance(service, InstanceSet):
            try:
                instance = self._pick_instance(service)
            except NotConnected as ex:
                logger.warning('cannot send request (%s) subject=%s', ex, subject)
                raise
            else:
                endpoint = instance.endpoint
                version = instance.version
        else:
            endpoint = service
            version = None

        msg = Message(
            msg_type=Message.REQ,
            subject=subject,
            body=body,
            source=self.endpoint,
            headers=self.prepare_headers(headers, version=serialize_version(version)),
        )
        channel = RequestChannel(msg, self)
        self.channels[msg.id] = channel
        self._send_message(endpoint, msg)
        return channel
Exemple #2
0
    def send_request(self, service, subject, body, headers=None):
        if isinstance(service, InstanceSet):
            try:
                instance = self._pick_instance(service)
            except NotConnected as ex:
                logger.warning('cannot send request (%s) subject=%s', ex,
                               subject)
                raise
            else:
                endpoint = instance.endpoint
                version = instance.version
        else:
            endpoint = service
            version = None

        msg = Message(
            msg_type=Message.REQ,
            subject=subject,
            body=body,
            source=self.endpoint,
            headers=self.prepare_headers(headers,
                                         version=serialize_version(version)),
        )
        channel = RequestChannel(msg, self)
        self.channels[msg.id] = channel
        self._send_message(endpoint, msg)
        return channel
Exemple #3
0
 def serialize(self):
     d = {
         'id': self.id,
         'identity': self.identity,
         'version': serialize_version(self.version),
     }
     d.update(self.info)
     return d
Exemple #4
0
 def get_instance_description(self, interface):
     description = interface.get_description()
     description.update({
         'id': interface.id,
         'endpoint': self.endpoint,
         'identity': self.identity,
         'log_endpoint': self.log_endpoint,
         'monitoring_endpoint': self.monitor.endpoint,
         'backdoor_endpoint': self.backdoor_endpoint,
         'fqdn': self.fqdn,
         'hostname': socket.gethostname(),
         'ip': self.server.ip,
         'type': self.worker,
         'version': serialize_version(interface.version),
     })
     return description
Exemple #5
0
 def get_instance_description(self, interface):
     description = interface.get_description()
     description.update({
         'id': interface.id,
         'endpoint': self.endpoint,
         'identity': self.identity,
         'log_endpoint': self.log_endpoint,
         'monitoring_endpoint': self.monitor.endpoint,
         'backdoor_endpoint': self.backdoor_endpoint,
         'fqdn': self.fqdn,
         'hostname': socket.gethostname(),
         'ip': self.server.ip,
         'type': self.worker,
         'version': serialize_version(interface.version),
     })
     return description
Exemple #6
0
 def handle_request(self, func_name, channel):
     method = self.methods[func_name]
     channel.add_header('version', serialize_version(self.version))
     method.rpc_call(self, channel, **channel.request.body)