コード例 #1
0
ファイル: client.py プロジェクト: PyHUBKyiv/python-nats
    def request(self, subject, data=None, blk=None, **opts):
        '''\
        Send a request and have the response delivered to the supplied callback.

        Params:
        =====
        subject: message subject;
        msg: message payload;
        callback: callback if any;

        Returns:
        =====
        sid: Subject Identifier
        '''
        if not self.conn.connected:
            raise NatsClientException("Connection losted")
        if not subject:
            return None
        inbox = Common.create_inbox()
        def process_reply(msg, reply):
            'closure block of request'
            args, _, _, _ = inspect.getargspec(blk)
            args_len = len(args)
            if args_len == 0:
                blk()
            elif args_len == 1:
                blk(msg)
            else:
                blk(msg, reply)
        sid = self.subscribe(inbox, process_reply, **opts)
        self.publish(subject, data, inbox)
        return sid
コード例 #2
0
ファイル: client.py プロジェクト: eodreports/python-nats
    def request(self, subject, data=None, blk=None, **opts):
        '''\
        Send a request and have the response delivered to the supplied callback.

        Params:
        =====
        subject: message subject;
        msg: message payload;
        callback: callback if any;

        Returns:
        =====
        sid: Subject Identifier
        '''
        if not self.conn.connected:
            raise NatsClientException("Connection losted")
        if not subject:
            return None
        inbox = Common.create_inbox()

        def process_reply(msg, reply):
            'closure block of request'
            args, _, _, _ = inspect.getargspec(blk)
            args_len = len(args)
            if args_len == 0:
                blk()
            elif args_len == 1:
                blk(msg)
            else:
                blk(msg, reply)

        sid = self.subscribe(inbox, process_reply, **opts)
        self.publish(subject, data, inbox)
        return sid
コード例 #3
0
ファイル: test_unit.py プロジェクト: eodreports/python-nats
 def test_create_inbox(self):
     'should return random INBOX name'
     inbox1 = Common.create_inbox()
     inbox2 = Common.create_inbox()
     assert '_INBOX' in inbox1
     assert inbox1 != inbox2
コード例 #4
0
ファイル: test_unit.py プロジェクト: PyHUBKyiv/python-nats
 def test_create_inbox(self):
     'should return random INBOX name'
     inbox1 = Common.create_inbox()
     inbox2 = Common.create_inbox()
     assert '_INBOX' in inbox1
     assert inbox1 != inbox2