4.1. Creating and Closing Clients and Sessions

4.1. Creating and Closing Clients and Sessions

All of the examples in this section use the same code to initialize the program, create a session, and clean up before exiting. They also use the same include files. The following skeleton can be used as the basis to write a wide variety of MRG Messaging applications in Python.


import qpid
from qpid.client import Client
from qpid.content import Content
from qpid.queue import Empty

#----- Initialization ----------------------------

#  Set parameters for login

host="127.0.0.1"
port=5672
amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml"
user="guest"
password="guest"

#  Create a client and log in to it.

client = Client(host, port, qpid.spec.load(amqp_spec))
client.start({"LOGIN": user, "PASSWORD": password})

session = client.session()
session.session_open()

#----- Main Body of Program-----------------------


#----- Cleanup -----------------------------------

# Close the session before exiting so there are no open threads.

session.session_close()