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


Python kafka.SimpleProducer方法代码示例

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


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

示例1: __init__

# 需要导入模块: import kafka [as 别名]
# 或者: from kafka import SimpleProducer [as 别名]
def __init__(self, kafka, chunk_size):
        self.producer = SimpleProducer(kafka)
        self.queues = {}
        self.chunk_size = chunk_size 
开发者ID:rwalk,项目名称:straw,代码行数:6,代码来源:tweet_sampler.py

示例2: produce_example_msg

# 需要导入模块: import kafka [as 别名]
# 或者: from kafka import SimpleProducer [as 别名]
def produce_example_msg(topic, num_messages=1):
    kafka = KafkaToolClient(KAFKA_URL)
    producer = SimpleProducer(kafka)
    for i in range(num_messages):
        try:
            producer.send_messages(topic, b'some message')
        except LeaderNotAvailableError:
            # Sometimes kafka takes a bit longer to assign a leader to a new
            # topic
            time.sleep(10)
            producer.send_messages(topic, b'some message') 
开发者ID:Yelp,项目名称:kafka-utils,代码行数:13,代码来源:util.py

示例3: setup

# 需要导入模块: import kafka [as 别名]
# 或者: from kafka import SimpleProducer [as 别名]
def setup(self):
        '''
        Connection stuff here so we can mock it
        '''
        self.redis_conn = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)

        # set up kafka
        self.kafka_conn = KafkaClient(KAFKA_HOSTS)
        self.producer = SimpleProducer(self.kafka_conn)
        self.topic_prefix = KAFKA_TOPIC_PREFIX 
开发者ID:openslack,项目名称:openslack-crawler,代码行数:12,代码来源:redis-monitor.py

示例4: __init__

# 需要导入模块: import kafka [as 别名]
# 或者: from kafka import SimpleProducer [as 别名]
def __init__(self, config):
    
        app = Flask(__name__)
        app.secret_key = 'i love to search full text in real time'

        # attach a redis connection pool
        app.pool = redis.ConnectionPool(host="localhost", port=6379)

        # user -> channels mapping
        app.user_channels = {}

        # how to handle messages that enter the stream from redis pub sub
        def redis_message_handler(msg):
            redis_connection = redis.Redis(connection_pool=app.pool)
            # get channel and content of incoming message
            channel = msg['channel']
            data = msg['data']

            # word highlighting -- TODO: this would be better to do in the search engine!
            query = redis_connection.get(channel)
            words = list(set(query.split(" ")))
            for w in words:
                data=data.lower().replace(w.lower(), highlight(w.lower()))

            # find users subscribed to this channel
            if app.user_channels.get(channel) is not None:
                for user in app.user_channels.get(channel):
                    redis_connection.lpush(user, data)
            else:
                # no more users for this channel, unsubscribe from it
                redis_connection.unsubscribe(channel)            
            
        # Add Redis query subscriber to app
        app.disp = []
        app.subscriber = QuerySubscriber("localhost", 6379, redis_message_handler)

        # setup kafka producer in the app
        kafka = KafkaClient("{0}:{1}".format(config["zookeeper_host"], 9092))
        app.producer = SimpleProducer(kafka)

        # add the app
        self.app = app 
开发者ID:rwalk,项目名称:straw,代码行数:44,代码来源:straw_app.py


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