コード例 #1
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ProducerPolicy(Response):
     SCHEMA = Schema(('nearby', Boolean),
                     ('single', Boolean),
                     ('archive', Boolean),
                     ('weight', Array(Weight)),
                     ('blackList', Array(UTF8String)),
                     ('timeout', Int32))
     TYPE = 'Producer Policy'
コード例 #2
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class Topic(Response):
    SCHEMA = Schema(('topicCode', UTF8String),
                    ('hasProducerPolicy', Boolean),
                    ('producerPolicy', ProducerPolicy),
                    ('hasConsumerPolicy', Boolean),
                    ('consumerPolicy', ConsumerPolicy),
                    ('type', Int8),
                    ('partitionGroups', Array(PartitionGroup)),
                    ('code', Int32))
    TYPE = 'Topic'

    def __init__(self, topic_code, hasProducerPolicy, producerPolicy,hasConsumerPolicy,consumerPolicy,type,partitionGroups,code):
        self.topicCode = topic_code
        self.hasProducerPolicy = hasProducerPolicy
        self.producerPolicy = producerPolicy
        self.hasConsumerPolicy = hasConsumerPolicy
        self.consumerPolicy = consumerPolicy
        self.type = type
        self.partitionGroups = partitionGroups
        self.code = code
        self.encode = WeakMethod(self._encode_self)

    def _encode_self(self):
        list = []
        list.append(self.SCHEMA.fields[0].encode(self.code))
        list.append(self.SCHEMA.fields[1].encode(self.hasProducerPolicy))
        if self.hasProducerPolicy:
            list.append(self.SCHEMA.fields[2].encode(self.producerPolicy))

        list.append(self.SCHEMA.fields[3].encode(self.hasConsumerPolicy))
        if self.hasConsumerPolicy:
            list.append(self.SCHEMA.fields[4].encode(self.consumerPolicy))

        list.append(self.SCHEMA.fields[5].encode(self.type))
        list.append(self.SCHEMA.fields[6].encode(self.partitionGroups))
        return b''.join(list)

    @classmethod
    def encode(cls, item):
        it = cls(*item)
        return it.encode()

    @classmethod
    def decode(cls, data):
        if isinstance(data, bytes):
            data = BytesIO(data)
        base_fields = cls.SCHEMA.fields[0:2]
        topic_code, has_producer_policy = [f.decode(data) for f in base_fields]
        producerPolicy = None
        consumerPolicy = None
        if has_producer_policy:
            producerPolicy = cls.SCHEMA.fields[2].decode(data)
        has_consumer_policy = cls.SCHEMA.fields[3].decode(data)
        if has_consumer_policy:
            consumerPolicy = cls.SCHEMA.fields[4].decode(data)
        type, partitionGroups, code = [f.decode(data) for f in cls.SCHEMA.fields[5:]]
        return cls(topic_code, has_producer_policy, producerPolicy, has_consumer_policy,
                   consumerPolicy, type, partitionGroups, code)
コード例 #3
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ProduceMessageRequest(Request):
    SCHEMA = Schema(('topics', Array(TopicProduceMessage)),
                    ('app', UTF8String))
    TYPE = PRODUCE_MESSAGE_REQUEST

    @classmethod
    def default_messages_request(cls, topic, producer, msg):
        msgs = [(msg, 'deault_bussiness_id', None, None, producer)]
        topic_messages = [(topic, None, 5000, 2, msgs)]
        return ProduceMessageRequest(topic_messages, producer)
コード例 #4
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class FetchMessageRequest(Request):
    SCHEMA = Schema(('topics', Array(FetchTopic)), ('app', UTF8String),
                    ('ackTimeout', Int32), ('longPollTimeout', Int32))
    TYPE = FETCH_TOPIC_MESSAGE_REQUEST

    @classmethod
    def default_fetch_message_request(cls, topic, app, batch_size):
        topics = [(topic, batch_size)]
        fetch_message = (topics, app, 5000, 10000)
        return FetchMessageRequest(*fetch_message)
コード例 #5
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ConsumerPolicy(Response):
     SCHEMA = Schema(('nearby', Boolean),
                     ('pause', Boolean),
                     ('archive', Boolean),
                     ('retry', Boolean),
                     ('seq', Boolean),
                     ('ackTimeout', Int32),
                     ('backSize', Int16),
                     ('concurrent', Boolean),
                     ('concurrentSize', Int32),
                     ('delay', Int32),
                     ('backList', Array(UTF8String)),
                     ('errTimes', Int32),
                     ('maxPartitionNum', Int32),
                     ('readRetryProportion', Int32))
     TYPE = 'Consumer policy'
コード例 #6
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ConsumerResponse(Response):
    SCHEMA = Schema(('consumerIds', Array(ConsumerId)))
    TYPE = ADD_CONSUMER_RESPONSE
コード例 #7
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ProducerResponse(Response):
    SCHEMA = Schema(('producerIds', Array(ProducerId)))
    TYPE = ADD_PRODUCER_RESPONSE
コード例 #8
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ConsumerRequest(Request):
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String),
                    ('sequence', Int64))
    TYPE = ADD_CONSUMER_REQUEST
コード例 #9
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class MetadataResponse(Response):
    SCHEMA = Schema(('topics', Array(Topic)),
                    ('brokers', Array(Broker)))
    TYPE = FETCH_CLUSTER_RESPONSE
コード例 #10
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class ProducerRequest(Request):
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String),
                    ('sequence', Int64))

    TYPE = ADD_PRODUCER_REQUEST
コード例 #11
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class FetchMessageResponse(Response):
    SCHEMA = Schema(('data', Array(TopicMessage)))
    TYPE = FETCH_TOPIC_MESSAGE_RESPONSE
コード例 #12
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class MetadataRequest(Request):
    # STR = String('utf-8')
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String))
    TYPE = FETCH_CLUSTER_REQUEST
コード例 #13
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ProduceMessageResponse(Response):
    SCHEMA = Schema(('data', Array(TopicProducePartitionAck)))
    TYPE = PRODUCE_MESSAGE_RESPONSE
コード例 #14
0
ファイル: test_codec.py プロジェクト: joypy/joyqueue-python
def test_array_string():
    topics = ['test_topic']
    bytes=Array(String()).encode(topics)
    print(bytes)
コード例 #15
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumeAck(Request):
    SCHEMA = Schema(('topics', Array(ConsumeTopicPartitionGroupAckResponse)),
                    ('app', UTF8String))
    TYPE = COMMIT_ACK_REQUEST
コード例 #16
0
ファイル: metadata.py プロジェクト: joypy/joyqueue-python
class PartitionGroup(Response):
     SCHEMA = Schema(('id', Int32),
                     ('leader', Int32),
                     ('partitions', Array(Int16)))
     TYPE = 'Partition Group'
コード例 #17
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumeTopicPartitionGroupAckResponse(Response):
    SCHEMA = Schema(('topic', UTF8String),
                    ('partitions', Array(ConsumePartitionAckResponse)))
    TYPE = 'Consume topic partition group ack'
コード例 #18
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumePartitionAckResponse(Response):
    SCHEMA = Schema(('partition', Int16),
                    ('data', Array(ConsumePartitionIndexAckResponse)))
    TYPE = 'Consume partition ack'
コード例 #19
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumePartitionGroupAck(Request):
    SCHEMA = Schema(('partition', Int16), ('data', Array(ConsumePartitionAck)))
    TYPE = 'Consume partition group ack'
コード例 #20
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class TopicProducePartitionAck(Request):
    SCHEMA = Schema(('topic', UTF8String), ('code', Int32),
                    ('result', Array(ProducePartitionAck)))
    TYPE = 'Topic partition ack'
コード例 #21
0
ファイル: test_codec.py プロジェクト: joypy/joyqueue-python
def test_struct_array():
    partition_groups = ((1, 1000000889, (1, 2)), (2, 1000000889, (3, 4)))
    pg = Array(PartitionGroup)
    bytes = pg.encode(partition_groups)
    receive = pg.decode(bytes)
    assert pg == receive
コード例 #22
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumeTopicPartitionAckState(Response):
    SCHEMA = Schema(('topic', UTF8String),
                    ('partitionData', Array(ConsumePartitionAckState)))
    TYPE = 'Consume topic partition ack state'
コード例 #23
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class TopicMessage(Request):
    SCHEMA = Schema(('topic', UTF8String), ('messages', Array(Message)),
                    ('code', Int32))
    TYPE = 'Topic produce message'
コード例 #24
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class ConsumeAckResponse(Response):
    SCHEMA = Schema(('data', Array(ConsumeTopicPartitionAckState)))
    TYPE = COMMIT_ACK_RESPONSE
コード例 #25
0
ファイル: message.py プロジェクト: joypy/joyqueue-python
class TopicProduceMessage(Request):
    SCHEMA = Schema(('topic', UTF8String), ('txId', UTF8String),
                    ('timeout', Int32), ('qosLevel', Int8),
                    ('messages', Array(Message)))
    TYPE = 'Topic produce message'