Exemplo n.º 1
0
    def __init__(self,
                 shared_recv_queue,
                 redis_host,
                 redis_port,
                 persistance=15,
                 dps_window=15,
                 replay_output_fname=None,
                 status_refresh_period=1,
                 debug=False):
        self.shared_recv_queue = shared_recv_queue
        self.redis_host = redis_host
        self.redis_port = redis_port
        self.dt_persistance = datetime.timedelta(seconds=persistance)
        self.dps_window = dps_window
        self.replay_output_fname = replay_output_fname
        self.dt_status_refresh_period = datetime.timedelta(
            seconds=status_refresh_period)
        self.debug = debug

        self.main_collection = {}
        self.replay_output = None
        self.recv_queue = queue.Queue()

        self.socket_io_emitter = Emitter({
            'host': self.redis_host,
            'port': self.redis_port
        })
        print("MedusaWorker : Emitter connected to " + str(self.redis_host) +
              ":" + str(self.redis_port))
        self.main_upkeep_loop()
Exemplo n.º 2
0
    def test_Emit(self):
        io = Emitter(self.opts)
        redis_cli = subprocess.Popen('redis-cli monitor', stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)

        output = ''
        while True:
            chunk = redis_cli.stdout.read(1).decode('utf-8')
            if chunk == '' and redis_cli.poll() != None:
                break
            if chunk == '\n':
                io.Emit('broadcast event', 'Hello from socket.io-emitter')
            if chunk != '' and 'PUBLISH' not in output:
                output += chunk
            else:
                redis_cli.kill()
                break

        self.assertTrue('PUBLISH' in output)
Exemplo n.º 3
0
    def _send_notification(self):
        io = Emitter({"client": config.REDIS_CLIENT})

        if self.request.get("broadcast"):
            io.Emit(
                f'ExperimentUpdates-{self.request["experimentId"]}',
                self._construct_response_msg(),
            )

            info(
                f"Broadcast results to users viewing experiment {self.request['experimentId']}."
            )

        io.Emit(f'WorkResponse-{self.request["ETag"]}',
                self._construct_response_msg())

        info(
            f"Notified users waiting for request with ETag {self.request['ETag']}."
        )
Exemplo n.º 4
0
from flask import Flask, Response
from flask_socketio import SocketIO, Namespace, emit

from kafka import KafkaConsumer
from kafka import TopicPartition
import numpy as np
import base64
import bz2
from socket_io_emitter import Emitter

io = Emitter({'host': 'localhost', 'port': 6379})

app = Flask(__name__)

socketio = SocketIO(app)
socketio.init_app(app, cors_allowed_origins="*")

consumer = KafkaConsumer(group_id='group1',
                         bootstrap_servers=['192.168.1.185:9092'],
                         fetch_max_bytes=700000)
consumer.assign([TopicPartition(topic="test17", partition=0)])


def print_message():
    for msg in consumer:
        if msg != None:
            # print(msg.value)
            img = msg.value
            b64 = bz2.decompress(img)
            img = base64.b64decode(b64)
            img = np.asarray(bytearray(img), dtype='uint8').tolist()
Exemplo n.º 5
0
 def test_Construct_Emitter_With_Options(self):
     io = Emitter(self.opts)
     self.assertIsNotNone(io._client)
Exemplo n.º 6
0
 def test_Construct_Emitter_With_Client(self):
     client = redis.StrictRedis(host=self.opts['host'], port=self.opts['port'])
     io = Emitter({'client': client})
     self.assertIsNotNone(io._client)
Exemplo n.º 7
0
 def test_Of(self):
     io = Emitter(self.opts)
     io.Of('nsp')
     self.assertEqual(io._flags['nsp'], 'nsp')
Exemplo n.º 8
0
 def test_To(self):
     io = Emitter(self.opts)
     io.To('room1')
     self.assertEqual(len(io._rooms), 1)