Beispiel #1
0
def main(argv):

    ledthread = Thread(target=led)
    ledthread.start()

    broker = "netapps.ece.vt.edu"
    vhost = "/2014/fall/sentry"
    login = "******"
    password = "******"
    rkey = "bennybene"

    message_broker = None
    channel = None
    try:
        # Connect to message broker
        message_broker = pika.BlockingConnection(
            pika.ConnectionParameters(host=broker,
                                      virtual_host=vhost,
                                      credentials=pika.PlainCredentials(
                                          login, password, True)))

        print "Connected to message broker"
        channel = message_broker.channel()
        channel.exchange_declare(exchange="alarms", type="direct")

        signal_num = signal.SIGINT
        # Create eventg handler if signal is caught
        try:
            channel_manager = StatsClientChannelHelper(channel)
            signal.signal(signal_num, channel_manager.stop_stats_client)
            signal_num = signal.SIGTERM
            signal.signal(signal_num, channel_manager.stop_stats_client)

        except ValueError, ve:
            print "Warning: Graceful shutdown may not be possible: Unsupported signal: " + signal_num

        # Create a queue to receive messages
        my_queue = channel.queue_declare(exclusive=True)

        # Bind the queue to the stats exchange
        channel.queue_bind(exchange="alarms",
                           queue=my_queue.method.queue,
                           routing_key=rkey)

        # Setup callback for when a subscribed message is received
        channel.basic_consume(on_new_msg,
                              queue=my_queue.method.queue,
                              no_ack=True)
        print "New message from broker"

        channel.start_consuming()
def main():

    url = 'amqps://*****:*****@fish.rmq.cloudamqp.com/kyiirjzl'
    parametros = pika.URLParameters(url)
    connection = pika.BlockingConnection(parametros)
    channel = connection.channel()
    channel.queue_declare(queue='Queue_Data')

    def callback(ch, method, properties, body):
        print(body.decode())

    channel.basic_consume(queue='Queue_Data',
                          auto_ack=True,
                          on_message_callback=callback)

    channel.start_consuming()
Beispiel #3
0
        notify_admin_by_email(message)


def main():
    # Check motes status every 60 seconds
    interval_monitor = setInterval(checkMotesInactive, 60)
    try:
        connection = pika.BlockingConnection(
            pika.ConnectionParameters(host=EVENT_SERVER))
        channel = connection.channel()
        channel.exchange_declare(exchange=EXCHANGE_READINGS, type='fanout')
        result = channel.queue_declare(exclusive=True)
        queue_name = result.method.queue
        channel.queue_bind(exchange=EXCHANGE_READINGS, queue=queue_name)
    except Exception, e:
        print("Error %s:" % e.args[0])
    finally:
        print 'Waiting for readings. To exit press CTRL+C'

    channel.basic_consume(callback, queue=queue_name, no_ack=True)
    try:
        channel.start_consuming()
    except:
        message = 'Error in connection to the event server'
        print message
        notify_admin_by_email(message)


if __name__ == "__main__":
    main()
Beispiel #4
0
        # as long as the client is connected

        result = channel.queue_declare(exclusive=True)
        queue_name = result.method.queue
        print "An exclusive queue declared successfully, now binding the queue and the exchange with the given routing key(s)"

        # Bind you queue to the message exchange, and register your new message event handler
        for topic in topics:
            channel.queue_bind(exchange='pi_utilization', queue=queue_name, routing_key=topic)
        print "Binding of exchange with the declared queue successful, now start pika's event loop by calling channel.basic_consume"

        # Start pika's event loop
        channel.basic_consume(on_new_msg, queue=queue_name, no_ack=True)
        print "Pika's event loop started"

        channel.start_consuming()

    except pika.exceptions.ProbableAccessDeniedError, pade:
        print >> sys.stderr, "Error: A Probable Access Denied Error occured: " + str(pade.message)

    except pika.exceptions.ProbableAuthenticationError, aue:
        print >> sys.stderr, "Error: A Probable Authentication error occured: " + str(aue.message)
    
    except pika.exceptions.AMQPConnectionError, acoe:
        print >> sys.stderr, "Error: An AMQP Connection Error occured: " + str(acoe.message)

    except pika.exceptions.AMQPChannelError, ache:
        print >> sys.stderr, "Error: An AMQP Channel Error occured: " + str(ache.message)
    
    except pika.exceptions.ChannelError, ce:
        print >> sys.stderr, "Error: A channel error occured: " + str(ce.message)