HP OneView Manual del usuario

Página 196

Advertising
background image

Ejemplo 7 Ejemplo de código Python (amqplib)

#!/usr/bin/env python

from optparse import OptionParser
from functools import partial

import amqp

def callback(channel, msg):
for key, val in msg.properties.items():
print ('%s: %s' % (key, str(val)))
for key, val in msg.delivery_info.items():
print ('> %s: %s' % (key, str(val)))

print ('')
print (msg.body)
print ('-------')
print msg.delivery_tag
channel.basic_ack(msg.delivery_tag)

#
# Cancel this callback
#
if msg.body == 'quit':
channel.basic_cancel(msg.consumer_tag)

def main():
parser = OptionParser()
parser.add_option('--host', dest='host',
help='AMQP server to connect to (default: %default)',
default='localhost',
)

options, args = parser.parse_args()
ssl_options = ({"ca_certs": "caroot.pem",
"certfile": "client.pem",
"keyfile": "key.pem",
# "cert_reqs": CERT_REQUIRED,
"server_side": False})

print ('Connecting to host %s' %options.host)

conn = amqp.Connection(options.host, login_method='EXTERNAL',
ssl=ssl_options)

print ('Successfully connected, creating and binding to queue')

ch = conn.channel()

196

Uso del bus State-Change Message Bus (SCMB)

Advertising