Exemplo n.º 1
0
    def test_create_frames(self):
        itr = ContentFrame.create_frames(42, 'helloworld', 13)

        frame = itr.next()
        assert_true(isinstance(frame, ContentFrame))
        assert_equals(42, frame.channel_id)
        assert_equals('hello', frame.payload)

        frame = itr.next()
        assert_true(isinstance(frame, ContentFrame))
        assert_equals(42, frame.channel_id)
        assert_equals('world', frame.payload)

        assert_raises(StopIteration, itr.next)
Exemplo n.º 2
0
    def test_create_frames(self):
        itr = ContentFrame.create_frames(42, 'helloworld', 13)

        frame = itr.next()
        assert_true(isinstance(frame, ContentFrame))
        assert_equals(42, frame.channel_id)
        assert_equals('hello', frame.payload)

        frame = itr.next()
        assert_true(isinstance(frame, ContentFrame))
        assert_equals(42, frame.channel_id)
        assert_equals('world', frame.payload)

        assert_raises(StopIteration, itr.next)
Exemplo n.º 3
0
    def publish(self, msg, exchange, routing_key, mandatory=False,
                immediate=False, ticket=None):
        '''
        publish a message.
        '''
        args = Writer()
        args.write_short(ticket or self.default_ticket).\
            write_shortstr(exchange).\
            write_shortstr(routing_key).\
            write_bits(mandatory, immediate)

        self.send_frame(MethodFrame(self.channel_id, 60, 40, args))
        self.send_frame(
            HeaderFrame(self.channel_id, 60, 0, len(msg), msg.properties))

        f_max = self.channel.connection.frame_max
        for f in ContentFrame.create_frames(self.channel_id, msg.body, f_max):
            self.send_frame(f)
Exemplo n.º 4
0
    def publish(self, msg, exchange, routing_key, mandatory=False,
                immediate=False, ticket=None):
        '''
        publish a message.
        '''
        args = Writer()
        args.write_short(ticket or self.default_ticket).\
            write_shortstr(exchange).\
            write_shortstr(routing_key).\
            write_bits(mandatory, immediate)

        self.send_frame(MethodFrame(self.channel_id, 60, 40, args))
        self.send_frame(
            HeaderFrame(self.channel_id, 60, 0, len(msg), msg.properties))

        f_max = self.channel.connection.frame_max
        for f in ContentFrame.create_frames(self.channel_id, msg.body, f_max):
            self.send_frame(f)