Exemple #1
0
import os
import time

from classes.CKafkaPC import KafkaPC

print("start 1p_count_up")

env_vars = {
    "config_path": os.getenv("config_path"),
    "config_section": os.getenv("config_section"),
}

new_p = KafkaPC(**env_vars)

for i in range(10):

    message = {"count": i * 2}
    new_p.send_msg(message)
    print(f"Sent message {i} with count={i*2}")
    time.sleep(1)
Exemple #2
0
import json
import os
from time import sleep
from classes.CKafkaPC import KafkaPC


def load_data(file):
    with open(file) as f:
        return json.load(f)


data = load_data("./data/plot_topic_200k_unfunktionabel.json")

env_vars = {
    'config_path': os.getenv('config_path'),
    'config_section': os.getenv('config_section')
}

new_pc = KafkaPC(**env_vars)

max_iteration = 100
iteration = 0
message_count = 0
while iteration < max_iteration:
    iteration += 1
    for row in data:
        message_count += 1
        print(f"Iteration {iteration}, Message {message_count}")
        new_pc.send_msg(row)
        sleep(0.02)
Exemple #3
0
    user_name: str
    user_location: str
    account_created_at: str
    statuses_count: int  # The number of Tweets (& retweets) issued by the user.
    favorites_count: int  # The number of Tweets this user has liked
    followers_count: int  # The number of followers this account currently has.
    friends_count: int  # The number of users this account is following
    verified: bool


env_vars = {
    "config_path": os.getenv("config_path"),
    "config_section": os.getenv("config_section"),
}

new_pc = KafkaPC(**env_vars)

user_info = [
    User(
        id_str="1234",
        user_name="user1",
        user_location="Cologne",
        account_created_at="2020-08-25 12:32",
        statuses_count=5,
        favorites_count=12,
        followers_count=7,
        friends_count=2,
        verified=True,
    ),
    User(
        id_str="1235",
Exemple #4
0
            "rmse": msgdata["rmse"],
            "CPU_ms": msgdata["CPU_ms"],
            "RAM": msgdata["RAM"],
        },
    }

    new_c.send_msg(new_data_point)
    print("model application message sent")


env_vars = {
    "config_path": os.getenv("config_path"),
    "config_section": os.getenv("config_section"),
}

new_c = KafkaPC(**env_vars)

plot_dict = new_c.config["PLOT_TOPIC"]

try:
    while True:
        msg = new_c.consumer.poll(0.1)

        if msg is None:
            continue

        elif msg.error() is not None:
            print(f"Error occured: {str(msg.error())}")

        else:
            # tests if msg.topic is in plot_dict and calls function from dict
Exemple #5
0
import json
import os
from time import sleep
from classes.CKafkaPC import KafkaPC


def load_data(file):
    with open(file) as f:
        return json.load(f)


data = load_data("./data/data.json")

env_vars = {
    'config_path': os.getenv('config_path'),
    'config_section': os.getenv('config_section')
}

new_pc = KafkaPC(**env_vars)

for topic, rows in data.items():
    # checks if topic is a valid outgoing topic as specified in config.yml
    if topic not in new_pc.out_topic:
        continue
    else:
        print(f"Send data for topic: {topic}")
        for row in rows:
            print(row)
            new_pc.send_msg(row, topic=topic)
            sleep(1)
Exemple #6
0
import os

from classes.CKafkaPC import KafkaPC

print("start 2c_print")

env_vars = {
    'config_path': os.getenv('config_path'),
    'config_section': os.getenv('config_section')
}

new_c = KafkaPC(**env_vars)
print("created KafkaPC")

try:
    while True:
        msg = new_c.consumer.poll(0.1)

        if msg is None:
            continue

        elif msg.error() is not None:
            print(f"Error occured: {str(msg.error())}")

        else:
            new_message = new_c.decode_msg(msg)
            print(f"Received on topic '{msg.topic()}': {new_message}")

except KeyboardInterrupt:
    pass