Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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