from kafka import KafkaConsumer, KafkaProducer
from util.task_args import get_kafka_binder_brokers, get_input_channel, get_output_channel, get_reverse_string
from util.http_server import HttpHealthServer
from ml_actor import Mlalgorithm

N = 4

consumer = KafkaConsumer(get_input_channel(),
                         bootstrap_servers=[get_kafka_binder_brokers()])
producer = KafkaProducer(bootstrap_servers=[get_kafka_binder_brokers()])
HttpHealthServer.run_thread()

m = Mlalgorithm()

w = [0.0 for i in range(N)]

while True:
    for message in consumer:
        x, y = list(
            map(lambda z: float(z),
                message.value.decode('utf-8').split(',')))
        w = m.calculate(x, y, w)
        print(w)
        producer.send(get_output_channel(),
                      bytes(','.join(map(str, w)), encoding='utf8'))
Beispiel #2
0
import json

from time import sleep
from kafka import KafkaConsumer, KafkaProducer, TopicPartition
from util.http_status_server import HttpHealthServer
from util.task_args import get_kafka_binder_brokers, get_input_channel, get_output_channel

import logging

logger = logging.getLogger('kafka')
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.INFO)

logger.warning("Test warning mesage logger 12345 helllo")

consumer = KafkaConsumer(bootstrap_servers=[get_kafka_binder_brokers()],
                         api_version=(0, 9),
                         group_id=None,
                         auto_offset_reset='latest')
producer = KafkaProducer(bootstrap_servers=[get_kafka_binder_brokers()],
                         api_version=(0, 9))

tp = TopicPartition("two-forty.input", 0)
consumer.assign([tp])
consumer.seek_to_end()

HttpHealthServer.run_thread()

counter = 0

while True:
Beispiel #3
0
#!/usr/bin/env python

import os
import sys

from kafka import KafkaConsumer, KafkaProducer
from util.http_status_server import HttpHealthServer
from util.task_args import get_kafka_binder_brokers, get_input_channel, get_output_channel, get_reverse_string

consumer = KafkaConsumer(get_input_channel(), bootstrap_servers=[get_kafka_binder_brokers()])
producer = KafkaProducer(bootstrap_servers=[get_kafka_binder_brokers()])

HttpHealthServer.run_thread()

while True:
    for message in consumer:
        output_message = message.value
        reverse_string = get_reverse_string()

        if reverse_string is not None and reverse_string.lower() == "true":
            output_message = "".join(reversed(message.value))

        producer.send(get_output_channel(), output_message)