예제 #1
0
def store_es(message):
    config = readconfig()

    host = config.get('ES', 'host') or 'localhost'
    port = config.get('ES', 'port') or 9200
    index = config.get('ES', 'index') or 'solomatic'

    es = Elasticsearch([{"host": host, "port": port}])
    es.index(index=index, doc_type="message", body=json.loads(message))
예제 #2
0
def publish(message):
    config = readconfig()

    host = config.get('RMQ', 'host') or 'localhost'
    user = config.get('RMQ', 'user')
    passwd = config.get('RMQ', 'passwd')
    exchange = config.get('RMQ', 'exchange')
    vhost = config.get('RMQ', 'vhost')

    cred = pika.PlainCredentials(username=user, password=passwd)
    connection = pika.BlockingConnection(pika.ConnectionParameters(virtual_host=vhost, host=host, credentials=cred))
    channel = connection.channel()
    channel.exchange_declare(exchange=exchange, type='fanout', durable=True)

    channel.basic_publish(exchange=exchange, routing_key='', body=message)
    connection.close()
예제 #3
0
def get_receiver(queue, durable):
    config = readconfig()

    host = config.get('RMQ', 'host') or 'localhost'
    user = config.get('RMQ', 'user')
    passwd = config.get('RMQ', 'passwd')
    exchange = config.get('RMQ', 'exchange')
    vhost = config.get('RMQ', 'vhost')

    cred = pika.PlainCredentials(username=user, password=passwd)
    connection = pika.BlockingConnection(pika.ConnectionParameters(host=host, virtual_host=vhost, credentials=cred))
    channel = connection.channel()

    channel.queue_declare(queue=queue, exclusive=True, durable=durable)
    channel.queue_bind(exchange=exchange, queue=queue)

    return channel
예제 #4
0
                for i in range(0, int(ret)):
                    blinkled(GREEN, 0.05, True)
                    time.sleep(0.1)
            else:
                for i in range(0, 6):
                    blinkled(RED, 0.02, True)
                    time.sleep(0.05)
        else:
            for i in range(0, 7):
                blinkled(RED, 0.02, True)
                time.sleep(0.05)
        conn.close()

    channel.basic_ack(delivery_tag=method_frame.delivery_tag)


config = readconfig()
server = config.get('TIMR', 'server') or 'timr.solongo.office'
uri = config.get('TIMR', 'uri') or '/api/cardreader?id='

logger = create_logger('call-timr.log')
logger.info('Call-Timr: Start')
init_gpio()

queue = 'call-timr'
channel = get_receiver(queue, False)
channel.basic_consume(on_message, queue)

logger.info('Start Consuming.')
channel.start_consuming()