def main():
    c = service
    s = RedisInfo().group_list()['state']
    n = 2
    p = multiprocessing.Process(target=processManager,
                                args=(
                                    '127.0.0.1',
                                    5871,
                                ))
    p.start()
    managerDict[1] = {'pid': p.pid, 'process_type': 'manager'}

    for x in s:
        try:
            p = multiprocessing.Process(target=processStart,
                                        args=(
                                            x,
                                            s[x],
                                            c,
                                        ))
            p.start()
            argsText = '%s %s %s' % (x, s[x], c)
            managerDict[n] = {
                'pid': p.pid,
                'process_type': 'child',
                'args': argsText
            }
            n = n + 1
        except KeyboardInterrupt:
            p.join()

    processWrite(str(managerDict))
#!/usr/bin/env python
import pika
import sys, os

import time

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
from Redis import RedisInfo

r = RedisInfo()
rabbitmq_cluster = 0
hostname, port, user, password, vhost, exchange_name, rabbitmq_number = r.rabbitmq(
    rabbitmq_cluster)

credentials = pika.PlainCredentials(user, password)
parameters = pika.ConnectionParameters(hostname, port, vhost, credentials)
connection = pika.BlockingConnection(parameters)

channel = connection.channel()

channel.exchange_declare(exchange=exchange_name, type='direct', durable=True)
#channel.queue_declare(queue='task_queue', durable=True)

n = 0
while True:
    message = "Rabbitmq Test 12345678 %d" % n

    channel.basic_publish(exchange='', routing_key='XKRX-CS-KR', body=message)
    """
	channel.basic_publish(exchange='',
	                      routing_key='task_queue',
	def __init__(self):
		RedisInfo.__init__(self)
		StateCB.__init__(self) #self.callback
		self.rabbitmq = self.rabbitmq()
		self.new_rabbitmq = copy.deepcopy(self.rabbitmq.keys())
		self.rabbitmq_cluster = 0
#!/usr/bin/env python
import pika
import sys, os
import time

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
from Redis import RedisInfo

r = RedisInfo()
rabbitmq_cluster = 0
hostname, port, user, password, vhost, exchange_name, rabbitmq_number = r.rabbitmq(rabbitmq_cluster)



credentials = pika.PlainCredentials( user, password )
parameters = pika.ConnectionParameters( hostname, port, vhost, credentials )
connection = pika.BlockingConnection( parameters )


channel = connection.channel()

channel.exchange_declare( exchange = exchange_name, type='direct' , durable=True)
channel.queue_declare(queue='task_queue_1', durable=True)
print ' [*] Waiting for messages. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] Received %r" % (body,)
    #time.sleep( body.count('.') )
    print " [x] Done"
    #ch.basic_ack(delivery_tag = method.delivery_tag)
import sys, os
import time
import zipfile


sys.path.append(os.environ['QUANT_HOME'] + '/lib')
from Redis import RedisInfo

redis = RedisInfo().rdm_master

directory = '/home/ec2-user/source/Quant/resource/cluster'
redis_file= '/home/ec2-user/source/Quant/resource/redis_file'


def file_open(f):
	return open(f, "rb").read()

def file_write(f, data):
	return open(f, 'wb').write(data)

# This would print all the files and directories
dirs = os.listdir( directory )
for file in dirs:
   file_name = os.path.basename(file)
   print "Redis Upload :", file,
   redis.set(file_name, file_open( directory + '/' + file))
   print "Complete!"

for file in dirs:
	print "Redis Write :", file,
	#file_write( redis_file + '/' + file, redis.get(file_name) )
예제 #6
0
import sys, os
import redis
from redis.sentinel import Sentinel, SentinelConnectionPool, ConnectionError, MasterNotFoundError, SlaveNotFoundError
import time

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
sys.path.append(os.environ['QUANT_HOME'] + '/callback')

import ConfigParser
from Redis import RedisInfo
cfg = ConfigParser.ConfigParser()
ini = os.environ['QUANT_HOME'] + '/etc/quant.ini'
cfg.read(ini)

r = RedisInfo()

n = 0
while True:
    r.master_publish('test', 'this will reach the listener %d' % n)
    time.sleep(1)
    n = n + 1
# -*- coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()

import gevent
import time, sys, os
from threading import Thread
from flask import Flask, render_template, session, request
from flask.ext.socketio import SocketIO, emit, join_room, leave_room, close_room, disconnect

#########################
# Quant Redis Configure #
#########################
sys.path.append(os.environ['QUANT_HOME'] + '/lib')
from Redis import RedisInfo
r = RedisInfo()
rds = r.redis_server
import Daemon
from CommonClass import Config
# quant config text file read
cfg = Config()
port = int(cfg.get('WebServer', 'port'))
##########################

app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
thread = None

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
sys.path.append(os.environ['QUANT_HOME'] + '/callback')

from CommonClass import Config
from DataCallBack import CallBack as DataCB
from StateCallBack import CallBack as StateCB
from ClassCallBack import CallBack as ClassCB
from Redis import RedisInfo
from Rabbitmq import RabbitMQClass

cfg = Config()
# current server ipaddress & process id
myaddress = eval(cfg.get('Server',
                         'ipaddress'))  #ifaddresses('eth0')[2][0]['addr']
service = RedisInfo().get('service')[myaddress]  #state, class, data
ppid = current_process()
pid_dir = cfg.get('Manager', 'pid_file')

# multiprocess message share
manager = Manager()
managerDict = manager.dict()
managerDict[0] = {
    'pid': ppid.pid,
    'process_type': 'parent',
    'ipaddress': myaddress,
    'service': service
}
#manager process or parent pid
managerDict[1] = {'pid': 0}
예제 #9
0
 def __init__(self):
     RedisInfo.__init__(self)
     StateCB.__init__(self)  #self.callback
     self.rabbitmq = self.rabbitmq()
     self.new_rabbitmq = copy.deepcopy(self.rabbitmq.keys())
     self.rabbitmq_cluster = 0
예제 #10
0
import sys, os
import redis
from redis.sentinel import Sentinel, SentinelConnectionPool, ConnectionError, MasterNotFoundError, SlaveNotFoundError
import time
import threading

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
sys.path.append(os.environ['QUANT_HOME'] + '/callback')
from Redis import RedisInfo

redis_r = RedisInfo().master


class Listener(threading.Thread):
    def __init__(self, r, channels):
        threading.Thread.__init__(self)
        self.redis = r
        self.pubsub = self.redis.pubsub()
        self.pubsub.subscribe(channels)

    def work(self, item):
        print item['channel'], ":", item['data']

    def run(self):
        for item in self.pubsub.listen():
            if item['data'] == "KILL":
                self.pubsub.unsubscribe()
                print self, "unsubscribed and finished"
                break
            else:
                self.work(item)
예제 #11
0
import sys, os
import time
import zipfile

sys.path.append(os.environ['QUANT_HOME'] + '/lib')
from Redis import RedisInfo

redis = RedisInfo().rdm_master

directory = '/home/ec2-user/source/Quant/resource/cluster'
redis_file = '/home/ec2-user/source/Quant/resource/redis_file'


def file_open(f):
    return open(f, "rb").read()


def file_write(f, data):
    return open(f, 'wb').write(data)


# This would print all the files and directories
dirs = os.listdir(directory)
for file in dirs:
    file_name = os.path.basename(file)
    print "Redis Upload :", file,
    redis.set(file_name, file_open(directory + '/' + file))
    print "Complete!"

for file in dirs:
    print "Redis Write :", file,