本文整理汇总了Python中qpid.messaging.Connection.establish方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.establish方法的具体用法?Python Connection.establish怎么用?Python Connection.establish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qpid.messaging.Connection
的用法示例。
在下文中一共展示了Connection.establish方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkAuth
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def checkAuth(self, user, password):
"""
This function checks a username / password combination using
the AMQP service' SASL configuration.
=============== ============
Parameter Description
=============== ============
user Username
password Password
=============== ============
``Return:`` Bool, success or failure
"""
# Strip username/password parts of url
url = "%s:%s" % (self.url['host'], self.url['port'])
# Don't allow blank authentication
if user == "" or password == "":
return False
try:
conn = Connection.establish(url, transport=self.url['transport'], username=user, password=password)
conn.close()
except ConnectionError as e:
self.log.debug("AMQP service authentication reports: %s" % str(e))
return False
except Exception as e:
self.log.critical("cannot proceed with authentication")
self.log.exception(e)
return False
return True
示例2: start
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def start(self):
"""
Enable AMQP queueing. This method puts up the event processor and
sets it to "active".
"""
self.log.debug("enabling AMQP queueing")
# Evaluate username
user = self.env.config.get("amqp.id", default=None)
if not user:
user = self.env.uuid
# Create initial broker connection
url = "%s:%s" % (self.url['host'], self.url['port'])
self._conn = Connection.establish(url, reconnect=self.reconnect,
username=user,
password=self.env.config.get("amqp.key"),
transport=self.url['transport'],
reconnect_interval=self.reconnect_interval,
reconnect_limit=self.reconnect_limit)
# Do automatic broker failover if requested
if self.env.config.get('amqp.failover', default=False):
auto_fetch_reconnect_urls(self._conn)
# Create event provider
self._eventProvider = EventProvider(self.env, self._conn)
示例3: __init__
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def __init__(self, url, receiver_name, sender_name='pulp.task', asserting=False, **options):
'''establishes a connection to given url; initializes session, sender and receiver'''
self.url = url
self.receiver_name = receiver_name
self.sender_name = sender_name
self._asserting = asserting
self.last_sent = None
self.last_fetched = None
self.session = Connection.establish(self.url, **options).session()
self.receiver = self.session.receiver("%s; {create: always}" % self.receiver_name)
self.sender = self.session.sender(self.sender_name)
self._timeout = None
示例4: __init__
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def __init__(self, url, domain="org.clacks", xquery=".", callback=None):
# Build connection
url = parseURL(url)
_url = "%s:%s" % (url['host'], url['port'])
self.__conn = Connection.establish(_url, reconnect=True,
username=url['user'],
password=url['password'],
transport=url['transport'],
reconnect_interval=3,
reconnect_limit=0)
# Do automatic broker failover if requested
#TODO: configure reconnect
#auto_fetch_reconnect_urls(self.__conn)
# Assemble subscription query
queue = 'event-listener-%s' % uuid4()
address = """%s; {
create: always,
delete:always,
node: {
durable: False,
x-declare: {
exclusive: True,
auto-delete: True }
},
link: {
x-bindings: [
{
exchange: '%s',
queue: %s,
key: event,
arguments: { xquery: %r}
}
]
}
}""" % (queue, domain, queue, xquery)
# Add processor for core.event queue
self.__callback = callback
self.__eventWorker = AMQPStandaloneWorker(
self.__conn,
r_address=address,
workers=1,
callback=self.__eventProcessor)
示例5: start
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def start(self):
"""
Enable AMQP queueing. This method puts up the event processor and
sets it to "active".
"""
self.log.debug("enabling AMQP queueing")
# Evaluate username
user = self.config.get("amqp.id", default=None)
if not user:
user = self.env.uuid
password = self.config.get("amqp.key")
# Create initial broker connection
url = "%s:%s" % (self.url['host'], self.url['port'])
self._conn = Connection.establish(url, reconnect=self.reconnect,
username=user,
password=password,
transport=self.url['transport'],
reconnect_interval=self.reconnect_interval,
reconnect_limit=self.reconnect_limit)
# Do automatic broker failover if requested
if self.config.get('amqp.failover', False):
auto_fetch_reconnect_urls(self._conn)
# Create event exchange
socket = connect(self.url['host'], self.url['port'])
if self.url['scheme'][-1] == 's':
socket = ssl(socket)
user = self.config.get("amqp.id", default=None)
if not user:
user = self.env.uuid
connection = DirectConnection(sock=socket,
username=user,
password=self.config.get("amqp.key"))
connection.start()
session = connection.session(str(uuid4()))
# pylint: disable=E1103
session.exchange_declare(exchange=self.env.domain, type="xml")
connection.close()
# Create event provider
self._eventProvider = EventProvider(self.env, self.getConnection())
示例6: get_args
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def get_args():
parser = argparse.ArgumentParser(description="print messages sent to a qpid exchange")
parser.add_argument("-e", "--exchange", help="name of a qpid exchange (default: amq.topic)", default="amq.topic")
parser.add_argument("-s", "--subject", help="message subject to bind to", required=False)
parser.add_argument("-a", "--address", help="hostname to connect to (default:localhost)", default="localhost")
parser.add_argument("-p", "--port", help="port to connect to (default: 5672)", default="5672")
parser.add_argument("-q", "--quiet", help="show message subject only", default=False, action="store_true")
return parser.parse_args()
args = get_args()
source = args.exchange
if args.subject:
source = "%s/%s" % (source, args.subject)
receiver = Connection.establish("%s:%s" % (args.address, args.port)).session().receiver(source)
try:
while True:
message = receiver.fetch()
if args.quiet:
print message.subject
else:
print "------------------"
print message
except KeyboardInterrupt:
print ""
示例7: get
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
consumers = get('/consumers/')
return [ c['id'] for c in consumers if c['notes'].get('_child-node', False) ]
def get_nodes_repos(node):
" Returns a child node's 'bound' repos."
bindings = get("/consumers/%s/bindings/" % (node))
return [ repo['repo_id'] for repo in bindings ]
if __name__ == '__main__':
args = get_args()
# qpid connection
address = "%s:%s" % (args.host, args.port)
receiver = Connection.establish(address).session().receiver(args.exchange)
try:
while True:
message = receiver.fetch()
json_message = json.loads(message.content)
if json_message['payload']['result'] == 'success':
repo_id = json_message['payload']['repo_id']
else:
continue
nodes = get_nodes()
for node in nodes:
repos = get_nodes_repos(node)
if repo_id in repos:
示例8: SetBroker
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def SetBroker(self, brokerUrl):
self.url = brokerUrl
self.connection = Connection.establish(self.url, **conn_options)
self.broker = BrokerAgent(self.connection)
示例9: __init__
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def __init__(self, address, **kwargs):
self._connection = Connection.establish(
address, client_properties={"qpid.ha-admin":1}, **kwargs)
self._agent = BrokerAgent(self._connection)
assert self._agent.getHaBroker(), "HA module not loaded in broker at: %s"%(address)
示例10: exit
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
from mock import MagicMock
from mock import patch
except ImportError:
print 'Cannot run test without python MagicMock'
print 'Please install MagicMock: pip install mock'
exit(3)
connection = None
broker = None
try:
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
# setup broker connection
connection = Connection.establish('127.0.0.1')
broker = BrokerAgent(connection)
# add test service busname
busname = 'test-lofarbus-%s' % (uuid.uuid1())
broker.addExchange('topic', busname)
# the system under test is the service and the rpc, not the RADatabase
# so, patch (mock) the RADatabase class during these tests.
# when the service instantiates an RADatabase it will get the mocked class.
with patch('lofar.sas.resourceassignment.database.radb.RADatabase', autospec=True) as MockRADatabase:
mock = MockRADatabase.return_value
# modify the return values of the various RADatabase methods with pre-cooked answers
mock.getTaskStatuses.return_value = [{'id': 1, 'name': 'opened'}, {'id': 2, 'name': 'scheduled'}]
mock.getTaskTypes.return_value = [{'id': 0, 'name': 'OBSERVATION'}, {'id': 1, 'name': 'PIPELINE'}]
mock.getResourceClaimStatuses.return_value = [{'id': 0, 'name': 'CLAIMED'},{'id': 1, 'name': 'ALLOCATED'},{'id': 2, 'name': 'CONFLICT'}]
示例11: __init__
# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
def __init__(self, address, **kwargs):
self._connection = Connection.establish(
address, client_properties={"qpid.ha-admin":1}, **kwargs)
self._agent = BrokerAgent(self._connection)