当前位置: 首页>>代码示例>>Python>>正文


Python SimpleProducer.stop方法代码示例

本文整理汇总了Python中kafka.producer.SimpleProducer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleProducer.stop方法的具体用法?Python SimpleProducer.stop怎么用?Python SimpleProducer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kafka.producer.SimpleProducer的用法示例。


在下文中一共展示了SimpleProducer.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: KafkaProducer

# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import stop [as 别名]
class KafkaProducer(KafkaBase, TerminatorBlock):
    """ A block for producing Kafka messages """

    version = VersionProperty("1.0.1")

    def __init__(self):
        super().__init__()
        self._producer = None

    def configure(self, context):
        super().configure(context)
        self._connect()

    def stop(self):
        self._disconnect()
        super().stop()

    def process_signals(self, signals, input_id='default'):
        msgs = []
        for signal in signals:
            if self.connected:
                try:
                    if type(signal) is not bytes:
                        signal = pickle.dumps(signal)
                except:
                    self.logger.exception(
                        "Signal: {0} could not be serialized".format(signal))
                    return
                msgs.append(signal)
            else:
                return

        try:
            if self.connected:
                self._producer.send_messages(self._encoded_topic, *msgs)
        except:
            self.logger.exception("Failure sending signal")

    def _connect(self):
        super()._connect()
        self._producer = SimpleProducer(self._kafka)

    def _disconnect(self):
        if self._producer:
            self._producer.stop()
            self._producer = None
        super()._disconnect()

    @property
    def connected(self):
        return super().connected and self._producer
开发者ID:nio-blocks,项目名称:kafka,代码行数:53,代码来源:kafka_producer_block.py

示例2: __init__

# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import stop [as 别名]
class KafkaProducer:

    def __init__(self,conn_pool,topic):
        self.conn_pool = conn_pool
        self.topic = topic
        self.kafka = KafkaClient(self.conn_pool)
        self.producer = SimpleProducer(self.kafka, async=True)

    def send(self,message):
        self.producer.send_messages(self.topic, message)

    def sendBulk(self,messages):
        self.producer.send_messages(self.topic, *messages)

    def close(self):
        self.producer.stop()
        self.kafka.close()
        self.kafka = None
        self.producer = None
开发者ID:Sotera,项目名称:Datawake-Legacy,代码行数:21,代码来源:kafka_producer.py

示例3: __init__

# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import stop [as 别名]
class Producer:
	'Simple kafka producer'

	def __init__(self, servers, topic):
		self.client = KafkaClient(servers)
		self.producer = SimpleProducer(self.client)
		self.topic = topic

	def current_time(self):
		return int(round(time.time() * 1000))

	def produce(self, mesnum):
		msg = json.dumps({'time': self.current_time(), 'data' : 'Hello - %s' % mesnum})
		self.producer.send_messages(self.topic, msg)

	def stop(self):
		if self.producer != None:
			self.producer.stop()
		if self.client != None:
			self.client.close()
开发者ID:jvovk,项目名称:kafka-python,代码行数:22,代码来源:kafka_producer_oop.py

示例4: int

# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import stop [as 别名]
import threading, sys, json, time
from kafka.client import KafkaClient
from kafka.producer import SimpleProducer
from datetime import datetime

if __name__ == "__main__":
	servers = sys.argv[1]
	topic = sys.argv[2]
	mesnum = int(sys.argv[3])
	interval = float(sys.argv[4])

	client = KafkaClient(servers)
	producer = SimpleProducer(client)

	current_time = lambda: int(round(time.time() * 1000))

	try:
		while mesnum > 0:
			msg = json.dumps({'time': current_time(), 'data' : 'Hello - %s' % mesnum})
			producer.send_messages(topic, msg)
			time.sleep(interval)
			mesnum -= 1
	except KeyboardInterrupt:
		print "Interrupted!"
	finally:
		producer.stop()
		client.close()
开发者ID:jvovk,项目名称:kafka-python,代码行数:29,代码来源:kafka_producer.py


注:本文中的kafka.producer.SimpleProducer.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。