當前位置: 首頁>>代碼示例>>Python>>正文


Python kafka.SimpleConsumer方法代碼示例

本文整理匯總了Python中kafka.SimpleConsumer方法的典型用法代碼示例。如果您正苦於以下問題:Python kafka.SimpleConsumer方法的具體用法?Python kafka.SimpleConsumer怎麽用?Python kafka.SimpleConsumer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在kafka的用法示例。


在下文中一共展示了kafka.SimpleConsumer方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: connect

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def connect(self):
        """ Connect to kafka and create a consumer.
        It uses config parameters to create a kafka-python
        KafkaClient and SimpleConsumer.
        """
        # Instantiate a kafka client connected to kafka.
        self.client = KafkaClient(
            self.config.broker_list,
            client_id=self.config.client_id
        )

        # Create a kafka SimpleConsumer.
        self.kafka_consumer = SimpleConsumer(
            client=self.client, topic=self.topic, partitions=self.partitions,
            **self.config.get_simple_consumer_args()
        )
        self.log.debug(
            "Connected to kafka. Topic %s, partitions %s, %s",
            self.topic,
            self.partitions,
            ','.join(['{0} {1}'.format(k, v) for k, v in
                      six.iteritems(self.config.get_simple_consumer_args())])
        )
        self.kafka_consumer.provide_partition_info() 
開發者ID:Yelp,項目名稱:yelp_kafka,代碼行數:26,代碼來源:consumer.py

示例2: __init__

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def __init__(self, *args, **kwargs):
        import kafka
        super(KafkaRandomReader, self).__init__(*args, **kwargs)
        brokers = self.read_option('brokers')
        group = self.read_option('group')
        topic = self.read_option('topic')

        client = kafka.KafkaClient(map(bytes, brokers))

        # TODO: Remove this comments when next steps are decided.
        # If resume is set to true, then child should not load initial offsets
        # child_loads_initial_offsets = False if settings.get('RESUME') else True

        # self.consumer = kafka.MultiProcessConsumer(client, group, topic, num_procs=1,
        #                                             child_loads_initial_offsets=child_loads_initial_offsets,
        #                                             auto_commit=False)

        self.consumer = kafka.SimpleConsumer(client, group, topic,
                                             auto_commit=False)

        self.decompress_fun = zlib.decompress
        self.processor = self.create_processor()
        self.partitions = client.get_partition_ids_for_topic(topic)

        self.logger.info(
            'KafkaRandomReader has been initiated. '
            'Topic: {}. Group: {}'.format(self.read_option('topic'), self.read_option('group')))

        self.logger.info('Running random sampling')
        self._reservoir = self.fill_reservoir()
        self.logger.info('Random sampling completed, ready to process batches') 
開發者ID:scrapinghub,項目名稱:exporters,代碼行數:33,代碼來源:kafka_random_reader.py

示例3: get_kafka_consumer

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def get_kafka_consumer(group, topic):
    client = get_kafka_client()
    return kafka.SimpleConsumer(
        client, group, topic,
        iter_timeout=app.config["CONSUMER_TIMEOUT"]
    ) 
開發者ID:travel-intelligence,項目名稱:flasfka,代碼行數:8,代碼來源:api.py

示例4: get_message

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def get_message(self, block=True, timeout=0.1):
        """Get message from kafka. It supports the same arguments of get_message
        in kafka-python SimpleConsumer.

        :param block: If True, the API will block till at least a message is fetched.
        :type block: boolean
        :param timeout: If block is True, the function will block for the specified
                        time (in seconds).
                        If None, it will block forever.

        :returns: a Kafka message
        :rtype: Message namedtuple, which consists of: partition number,
                offset, key, and message value
        """
        fetched_message = self.kafka_consumer.get_message(block, timeout)
        if fetched_message is None:
            # get message timed out returns None
            return None
        else:
            partition, kafka_message = fetched_message
            return Message(
                partition=partition,
                offset=kafka_message[0],
                key=kafka_message[1].key,
                value=kafka_message[1].value,
            ) 
開發者ID:Yelp,項目名稱:yelp_kafka,代碼行數:28,代碼來源:consumer.py

示例5: get_consumer

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def get_consumer(containers, topic):
    kafka = containers.get_kafka_connection()
    group = str('replication_handler_itest')
    return SimpleConsumer(kafka, group, topic) 
開發者ID:Yelp,項目名稱:mysql_streamer,代碼行數:6,代碼來源:conftest.py

示例6: setup_capture_new_messages_consumer

# 需要導入模塊: import kafka [as 別名]
# 或者: from kafka import SimpleConsumer [as 別名]
def setup_capture_new_messages_consumer(topic):
    """Seeks to the tail of the topic then returns a function that can
    consume messages from that point.
    """
    kafka = KafkaClient(get_config().cluster_config.broker_list)
    group = str('data_pipeline_clientlib_test')
    consumer = SimpleConsumer(kafka, group, topic, max_buffer_size=_ONE_MEGABYTE)
    consumer.seek(0, 2)  # seek to tail, 0 is the offset, and 2 is the tail

    yield consumer

    kafka.close() 
開發者ID:Yelp,項目名稱:data_pipeline,代碼行數:14,代碼來源:kafka_docker.py


注:本文中的kafka.SimpleConsumer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。