Beispiel #1
0
class ProducerPolicy(Response):
     SCHEMA = Schema(('nearby', Boolean),
                     ('single', Boolean),
                     ('archive', Boolean),
                     ('weight', Array(Weight)),
                     ('blackList', Array(UTF8String)),
                     ('timeout', Int32))
     TYPE = 'Producer Policy'
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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'
Beispiel #6
0
class ConsumerResponse(Response):
    SCHEMA = Schema(('consumerIds', Array(ConsumerId)))
    TYPE = ADD_CONSUMER_RESPONSE
Beispiel #7
0
class ProducerResponse(Response):
    SCHEMA = Schema(('producerIds', Array(ProducerId)))
    TYPE = ADD_PRODUCER_RESPONSE
Beispiel #8
0
class ConsumerRequest(Request):
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String),
                    ('sequence', Int64))
    TYPE = ADD_CONSUMER_REQUEST
Beispiel #9
0
class MetadataResponse(Response):
    SCHEMA = Schema(('topics', Array(Topic)),
                    ('brokers', Array(Broker)))
    TYPE = FETCH_CLUSTER_RESPONSE
Beispiel #10
0
class ProducerRequest(Request):
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String),
                    ('sequence', Int64))

    TYPE = ADD_PRODUCER_REQUEST
Beispiel #11
0
class FetchMessageResponse(Response):
    SCHEMA = Schema(('data', Array(TopicMessage)))
    TYPE = FETCH_TOPIC_MESSAGE_RESPONSE
Beispiel #12
0
class MetadataRequest(Request):
    # STR = String('utf-8')
    SCHEMA = Schema(('topics', Array(UTF8String)),
                    ('app', UTF8String))
    TYPE = FETCH_CLUSTER_REQUEST
Beispiel #13
0
class ProduceMessageResponse(Response):
    SCHEMA = Schema(('data', Array(TopicProducePartitionAck)))
    TYPE = PRODUCE_MESSAGE_RESPONSE
Beispiel #14
0
def test_array_string():
    topics = ['test_topic']
    bytes=Array(String()).encode(topics)
    print(bytes)
Beispiel #15
0
class ConsumeAck(Request):
    SCHEMA = Schema(('topics', Array(ConsumeTopicPartitionGroupAckResponse)),
                    ('app', UTF8String))
    TYPE = COMMIT_ACK_REQUEST
Beispiel #16
0
class PartitionGroup(Response):
     SCHEMA = Schema(('id', Int32),
                     ('leader', Int32),
                     ('partitions', Array(Int16)))
     TYPE = 'Partition Group'
Beispiel #17
0
class ConsumeTopicPartitionGroupAckResponse(Response):
    SCHEMA = Schema(('topic', UTF8String),
                    ('partitions', Array(ConsumePartitionAckResponse)))
    TYPE = 'Consume topic partition group ack'
Beispiel #18
0
class ConsumePartitionAckResponse(Response):
    SCHEMA = Schema(('partition', Int16),
                    ('data', Array(ConsumePartitionIndexAckResponse)))
    TYPE = 'Consume partition ack'
Beispiel #19
0
class ConsumePartitionGroupAck(Request):
    SCHEMA = Schema(('partition', Int16), ('data', Array(ConsumePartitionAck)))
    TYPE = 'Consume partition group ack'
Beispiel #20
0
class TopicProducePartitionAck(Request):
    SCHEMA = Schema(('topic', UTF8String), ('code', Int32),
                    ('result', Array(ProducePartitionAck)))
    TYPE = 'Topic partition ack'
Beispiel #21
0
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
Beispiel #22
0
class ConsumeTopicPartitionAckState(Response):
    SCHEMA = Schema(('topic', UTF8String),
                    ('partitionData', Array(ConsumePartitionAckState)))
    TYPE = 'Consume topic partition ack state'
Beispiel #23
0
class TopicMessage(Request):
    SCHEMA = Schema(('topic', UTF8String), ('messages', Array(Message)),
                    ('code', Int32))
    TYPE = 'Topic produce message'
Beispiel #24
0
class ConsumeAckResponse(Response):
    SCHEMA = Schema(('data', Array(ConsumeTopicPartitionAckState)))
    TYPE = COMMIT_ACK_RESPONSE
Beispiel #25
0
class TopicProduceMessage(Request):
    SCHEMA = Schema(('topic', UTF8String), ('txId', UTF8String),
                    ('timeout', Int32), ('qosLevel', Int8),
                    ('messages', Array(Message)))
    TYPE = 'Topic produce message'