def __init__(self, host='localhost', port=5672, ssl=None): ''' Connect to QPID and make bindings to route message to external.dropbox queue @param host: string hostname of computer running EDEX and QPID (default localhost) @param port: integer port used to connect to QPID (default 5672) @param ssl: boolean to determine whether ssl is used, default value of None will use ssl only if a client certificate is found. ''' try: # socket = connect(host, port) if "QPID_SSL_CERT_DB" in os.environ: certdb = os.environ["QPID_SSL_CERT_DB"] else: certdb = os.path.expanduser("~/.qpid/") if "QPID_SSL_CERT_NAME" in os.environ: certname = os.environ["QPID_SSL_CERT_NAME"] else: certname = QPID_USERNAME certfile = os.path.join(certdb, certname + ".crt") if ssl or (ssl is None and os.path.exists(certfile)): keyfile = os.path.join(certdb, certname + ".key") trustfile = os.path.join(certdb, "root.crt") socket = qpid.util.ssl(socket, keyfile=keyfile, certfile=certfile, ca_certs=trustfile) self.connection = Connection (sock=socket, username=QPID_USERNAME, password=QPID_PASSWORD) self.connection.start() self.session = self.connection.session(str(uuid4())) self.session.exchange_bind(exchange='amq.direct', queue='external.dropbox', binding_key='external.dropbox') print 'Connected to Qpid' except: print 'Unable to connect to Qpid'
def __init__(self, broker, **kw): self.set_broker(broker) self.socket = connect(self.host, self.port) if self.url.scheme == URL.AMQPS: self.socket = ssl(self.socket) self.connection = Connection(sock=self.socket, username=self.user, password=self.password) self.connection.start() log.info("Connected to AMQP Broker %s" % self.host) self.session = self.connection.session(str(uuid4()))
def __init__(self, host='localhost', port=5672, timeout=5): self.__conn = self.__session = None if __debug__: print 'Connecting to %s:%d' % (host, port) qpid.util.socket.setdefaulttimeout(timeout) sock = qpid.util.connect(host, port) self.__conn = Connection(sock=sock) self.__conn.start() self.__session = self.__conn.session(str(uuid4()))
class TestBase010(unittest.TestCase): """ Base class for Qpid test cases. using the final 0-10 spec """ DEFAULT_USERNAME = "******" DEFAULT_PASSWORD = "******" DEFAULT_PORT = 5672 DEFAULT_PORT_TLS = 5671 def configure(self, config): self.config = config self.broker = config.broker self.defines = self.config.defines def setUp(self): self.conn = self.connect() self.session = self.conn.session("test-session", timeout=10) self.qmf = None self.test_queue_name = self.id() def startQmf(self, handler=None): self.qmf = qmf.console.Session(handler) self.qmf_broker = self.qmf.addBroker(str(self.broker)) def startBrokerAccess(self): """ New-style management access to the broker. Can be used in lieu of startQmf. """ if 'broker_conn' not in self.__dict__: self.broker_conn = qpid.messaging.Connection(str(self.broker)) self.broker_conn.open() self.broker_access = BrokerAgent(self.broker_conn) def connect(self, host=None, port=None): url = self.broker if url.scheme == URL.AMQPS: default_port = self.DEFAULT_PORT_TLS else: default_port = self.DEFAULT_PORT try: sock = connect(host or url.host, port or url.port or default_port) except socket.error, e: raise Skipped(e) if url.scheme == URL.AMQPS: sock = ssl(sock) conn = Connection(sock, username=url.user or self.DEFAULT_USERNAME, password=url.password or self.DEFAULT_PASSWORD) try: conn.start(timeout=10) except VersionError, e: raise Skipped(e)
def get_qpid_connection(broker_host): try: socket = connect(broker_host, 5672) connection = Connection(sock=socket, username=QPID_USERNAME, password=QPID_PASSWORD) connection.start() return connection except: sys.stderr.write("mhsAckNotify: connect to %s: %s\n" % ( broker_host, sys.exc_info()[1], )) return None
def __init__(self, hub, config): self.config = config self.set_broker(self.config.get('amqp_broker')) self.socket = connect(self.host, self.port) if self.url.scheme == URL.AMQPS: self.socket = ssl(self.socket) self.connection = Connection(sock=self.socket, username=self.user, password=self.password) self.connection.start() log.info("Connected to AMQP Broker %s" % self.host) self.session = self.connection.session(str(uuid4())) self.local_queues = [] super(QpidAMQPHubExtension, self).__init__()
def __init__(self, disp, host, username="******", password="******"): self.lock = Lock() self.tables = {} self.schema = {} self.bootSequence = 0 self.operational = False self.disp = disp self.cli = None self.lastUnit = None self.methodSeq = 1 self.methodsPending = {} self.sessionId = "%s.%d" % (platform.uname()[1], os.getpid()) self.broker = Broker(host) sock = connect(self.broker.host, self.broker.port) oldTimeout = sock.gettimeout() sock.settimeout(10) self.conn = Connection(sock, username=self.broker.username, password=self.broker.password) def aborted(): raise Timeout( "Waiting for connection to be established with broker") oldAborted = self.conn.aborted self.conn.aborted = aborted self.conn.start() sock.settimeout(oldTimeout) self.conn.aborted = oldAborted self.mclient = managementClient("unused", self.ctrlHandler, self.configHandler, self.instHandler, self.methodReply, self.closeHandler) self.mclient.schemaListener(self.schemaHandler) self.mch = self.mclient.addChannel(self.conn.session(self.sessionId)) self.operational = True self.idMap = {} self.idBackMap = {} self.nextId = 101
def __init__(self, host='localhost', port=5672): ''' Connect to QPID and make bindings to route message to external.dropbox queue @param host: string hostname of computer running EDEX and QPID (default localhost) @param port: integer port used to connect to QPID (default 5672) ''' try: # self.socket = connect(host, port) self.connection = Connection(sock=self.socket, username=QPID_USERNAME, password=QPID_PASSWORD) self.connection.start() self.session = self.connection.session(str(uuid4())) self.session.exchange_bind(exchange='amq.direct', queue='external.dropbox', binding_key='external.dropbox') print('Connected to Qpid') except: print('Unable to connect to Qpid')
class TestBase010(unittest.TestCase): """ Base class for Qpid test cases. using the final 0-10 spec """ def configure(self, config): self.config = config self.broker = config.broker self.defines = self.config.defines def setUp(self): self.conn = self.connect() self.session = self.conn.session("test-session", timeout=10) self.qmf = None def startQmf(self, handler=None): self.qmf = qmf.console.Session(handler) self.qmf_broker = self.qmf.addBroker(str(self.broker)) def connect(self, host=None, port=None): url = self.broker if url.scheme == URL.AMQPS: default_port = 5671 else: default_port = 5672 try: sock = connect(host or url.host, port or url.port or default_port) except socket.error, e: raise Skipped(e) if url.scheme == URL.AMQPS: sock = ssl(sock) conn = Connection(sock, username=url.user or "guest", password=url.password or "guest") try: conn.start(timeout=10) except VersionError, e: raise Skipped(e)
def get_session(self, user, passwd): socket = connect(self.broker.host, self.broker.port) connection = Connection (sock=socket, username=user, password=passwd, mechanism="PLAIN") connection.start() return connection.session(str(uuid4()))
def setup_connection(self): socket = connect(self._broker.host(), self._broker.port()) return Connection(sock=socket)
dest="debug", action="store_true", help="debug what messages are being sent") options, args = parser.parse_args() options.targets = [t.strip() for t in options.targets.split(',')] # Create connection and session session_dicts = [] for target in options.targets: print "Attempting to setup connection with", target try: socket = connect(target, 5672) connection = Connection( socket, username='******', password='******', ) connection.start(timeout=10000) session = connection.session(str(uuid4())) # Setup routing properties print "Talking to %s on topic %s" % (target, options.topic) properties = session.delivery_properties(routing_key=options.topic) session_dicts.append({ 'target': target, 'socket': socket, 'connection': connection, 'session': session, 'properties': properties, })
# Any functions and classes needed for a given example # go here. #----- Initialization ----------------------------------- # Set parameters for login host = "127.0.0.1" port = 5672 user = "******" password = "******" # Create a connection and a session. The constructor for a session # requires a UUID to uniquely identify the session. socket = connect(host, port) connection = Connection(sock=socket) connection.start() session = connection.session(str(uuid4())) print connection #----- Main Body of Program -------------------------------- # Main body of each example goes here #----- Cleanup --------------------------------------------- # Close the session before exiting so there are no open threads. session.close(timeout=10)
from qpid.connection import Connection from qpid.util import connect from qpid.session import Session import qpid.delegate import time from qpid.datatypes import Message, RangedSet, serial from qpid.ops import * logging.basicConfig(level=logging.DEBUG) address = "amq.topic" sock = connect("127.0.0.1", "5672") conn = Connection(sock, username="******", password="******", vhost="/ssw", client_properties={"client_process": "aa"}) conn.start(timeout=10000) session = conn.session("PYTHON_SESSION") time.sleep(5) session.queue_declare(queue="test-queue", exclusive=True, auto_delete=True) session.exchange_declare("test", "direct") session.exchange_bind(queue="test-queue", exchange="test", binding_key="key") session.message_subscribe(queue="test-queue", destination="consumer_tag", accept_mode=session.accept_mode.none,