当前位置: 首页>>代码示例>>Python>>正文


Python Connection.session方法代码示例

本文整理汇总了Python中qpid.messaging.Connection.session方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.session方法的具体用法?Python Connection.session怎么用?Python Connection.session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qpid.messaging.Connection的用法示例。


在下文中一共展示了Connection.session方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FreshDocWriter

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
class FreshDocWriter(PageWriterBase):
  def _initialize(self):
    self.set_name('FreshDocWriter')
    if get_project_settings()['DEBUG_MODE']:
      self._push_message = self._push_message_debug
    else:
      self._create_client()

  def _create_client(self):
    try:
      self.connection_ = Connection(url='10.100.151.13:5672', heartbeat=4, reconnect=True,
                                    reconnect_limit=10, reconnect_interval=4)
      self.connection_.open()
      self.sender_ = self.connection_.session().sender('leso.exchange.fresh_video')
    except:
      self.connection_ = None
      self.logger_.exception('failed to connect to message queue server.')

  def finalize(self):
    if self.connection_:
      self.connection_.close()
    PageWriterBase.finalize(self)

  def _push_message_debug(self, doc):
    pass

  def _push_message(self, doc):
    doc.video.doc_id = doc.id
    doc.video.id = str(doc.id)
    doc.video.crawl_time = doc.video.create_time = doc.crawl_time
    doc.video.discover_time = doc.discover_time
    doc.video.url = doc.url
    doc.video.domain = doc.domain
    doc.video.domain_id = doc.domain_id
    doc.video.in_links = doc.in_links
    msg_body = thrift_to_str(doc.video)
    if not msg_body:
      return
    self.sender_.send(Message(content=doc.url + '\t' + base64.b64encode(msg_body), durable=True))
    self.logger_.info('send message successfully, %s', doc.url)

  def process_item(self, item):
    if not item:
      return
    doc = item.to_crawldoc()
    if doc.doc_type != CrawlDocType.PAGE_TIME:
      return
    try:
      self._push_message(doc)
    except:
      self.logger_.exception('failed to send message, %s', doc.url)
开发者ID:cfhb,项目名称:crawl_youtube,代码行数:53,代码来源:fresh_doc_writer.py

示例2: SetupTests

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
class SetupTests(Base):

  def testOpen(self):
    # XXX: need to flesh out URL support/syntax
    self.conn = Connection.open(self.broker.host, self.broker.port,
                                reconnect=self.reconnect())
    self.ping(self.conn.session())

  def testConnect(self):
    # XXX: need to flesh out URL support/syntax
    self.conn = Connection(self.broker.host, self.broker.port,
                           reconnect=self.reconnect())
    self.conn.connect()
    self.ping(self.conn.session())

  def testConnectError(self):
    try:
      self.conn = Connection.open("localhost", 0)
      assert False, "connect succeeded"
    except ConnectError, e:
      # XXX: should verify that e includes appropriate diagnostic info
      pass
开发者ID:KeithLatteri,项目名称:awips2,代码行数:24,代码来源:messaging.py

示例3: Qpid

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
class Qpid(MQ):
    _timeout = 1

    def _conectar(self):
        try:
            logger.debug("Qpid: %s" % self._url.netloc)
            self._conn = Connection(self._url.netloc)
            if not self._conn:
                raise MQError(None, 2)
            self._conn.open()
        except ConnectError:
            raise MQError(cod=2)
        try:
            self._session = self._conn.session()
            self._sender = self._session.sender(self._url.path[1:])
            self._receiver = self._session.receiver(self._url.path[1:])
            logger.info("Connected on queue %s on %s" % (self._url.path[1:], self._url.netloc))
        except ConnectError:
            raise MQError(cod=3)

    def _enviar(self, mensagem):
        logger.debug("Sending a message")
        m = Message(mensagem)
        self._sender.send(m, True, self._timeout)

    def _receber(self, timeout=None):
        logger.debug("Retrieving a message")
        self._mensagem = self._receiver.fetch(timeout)
        return self._mensagem.content

    def _tamanho(self):
        self._receiver.available()

    def _excluir(self):
        logger.debug("Ack last message")
        self._session.acknowledge()

    def _terminar(self):
        self._conn.close(self._timeout)
开发者ID:cetres,项目名称:enviosms,代码行数:41,代码来源:_qpid.py

示例4: QpidConnection

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
class QpidConnection():

    port = None
    ip = None
    data_queue = None
    cmd_queue = None
    conn = None
    session = None
    sender = None
    receiver = None

    def __init__(self, ip, port, data_queue, cmd_queue):
            self.ip = ip;
            self.port = port
            self.data_queue = data_queue
            self.cmd_queue = cmd_queue

    def start(self):
        try:
            url = str(self.ip)
            url += str(':')
            url += str(self.port)
            self.conn = Connection(url)
            self.conn.open()
            self.session = self.conn.session()
            self.sender = self.session.sender(self.cmd_queue)
            self.receiver = self.session.receiver(self.data_queue)
            return 1
        except MessagingError as m:
            print(m)
            return 0

    def stop(self):
        try:
            self.conn.close()
        except MessagingError as m:
            print(m)
            return 0
开发者ID:fredimartins,项目名称:qpid_protobuf_python,代码行数:40,代码来源:Qpid.py

示例5: len

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
from qpid.messaging import Connection, Message
from time import sleep
import sys

host = "localhost:10009"
if len(sys.argv) > 1:
  host = sys.argv[1]

conn = Connection(host)
try:
  conn.open()
  sess = conn.session()
  tx = sess.sender("spfdemo.com/mobile.45")
  count = 0
  while(True):
    tx.send("Seq: %d" % count)
    print "Origin: %s Seq: %d" % (host, count)
    count += 1
    sleep(1)
except Exception, e:
  print "Exception: %r" % e
except KeyboardInterrupt:
  print
开发者ID:ted-ross,项目名称:qpid-spf,代码行数:25,代码来源:sender.py

示例6: RpcConnectionQpidMQ

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
class RpcConnectionQpidMQ(RpcConnection):
	def __init__(self,ep=None):
		RpcConnection.__init__(self,ep=ep)
		self.conn = None
		self.exitflag = False
		ep.impl = self
		self.mq_recv =''
		RpcConnectionMQ_Collection.instance().add(self)

	@staticmethod
	def create(name,host,port,address,af=AF_WRITE):
		"""
		创建MQ的连接对象
		:param name: 必须是真实的 mq 名称
		:param host:
		:param port:
		:param address:
		:param af:
		:return:
		"""
		ep = RpcEndPoint(name=name,host=host,port=port,addr=address,type_='qpid')
		if ep.open(af):
			return ep.impl
		return None
		# conn = RpcConnectionQpidMQ(ep)
		# conn.open(af)
		# return conn

	# @staticmethod
	# def createRpcInvocationPair(ep_read,ep_write):
	# 	conn_read = RpcConnectionQpidMQ(ep_read)
	# 	conn_read.open(AF_READ)
	# 	conn_write = RpcConnectionQpidMQ(ep_write)
	# 	conn_write.open(AF_WRITE)
	# 	conn_write.setLoopbackMQ(conn_read)
	# 	return conn_read,conn_write

	def open(self,af):
		'''
			<ep name="mq_gwa_2" address="mq_gwa_2;{create:always,node:{type:queue,durable:true}}" type="mq" host="127.0.0.1" port="5672"/>
			<ep name="mq_gwa_broadcast" address="mq_gwa_broadcast;{create:always,node:{type:topic,durable:true}}" type="mq" host="127.0.0.1" port="5672"/>
		'''
		from qpid.messaging import Connection
		from qpid.util import URL

		ep = self.ep
		self.af = af
		self.exitflag = False

		broker = "%s:%s"%(ep.host,ep.port)
		# log_debug('prepare mq : <%s %s>!'% (ep.name,broker))
		try:
			self.conn = Connection( broker,reconnect= True,tcp_nodelay=True)
			self.conn.open()
			self.ssn = self.conn.session()

			if af & AF_READ:
				self.rcv = self.ssn.receiver(self.ep.addr)
				self.rcv.capacity = 4000

				# self.thread = threading.Thread(target =self.thread_recv)
				# self.thread.start()
				# import gevent
				gevent.spawn(self.thread_recv)

			if af & AF_WRITE:
				self.snd = self.ssn.sender(self.ep.addr)

		except:
			log_error(traceback.format_exc())
			return False
		# log_debug('prepare mq : <%s %s> okay!'% (ep.name,broker))
		return True

	def close(self):
		if self.conn:
			self.conn.close()
			self.conn = None
			self.exitflag = True

	def setLoopbackMQ(self,conn_recv):
		'''
			设置rpc调用的回路连接, mq_recv为回路mq的名称, mq在EasyMQ_Collection中被缓存
			目前的回路mq名称取 队列名称,如果携带主机信息的话,回路可以从另外一台mq-server返回
		'''
		self.mq_recv = conn_recv.ep.getUnique()
		return self

	def sendMessage(self,m):


		if m.traits and  m.traits.max_linger_time:
			value = m.extra.props.get(RpcMessageTraits.MAX_MSG_LINGER_TIME,'0')
			value = int(value)
			if not value:
				value +=  int(time.time())
				m.extra.setPropertyValue(RpcMessageTraits.MAX_MSG_LINGER_TIME, value )

			#app制定了超时接收时间,这里调整为绝对时间,以便接收端进行判别,选择接受还是丢弃

#.........这里部分代码省略.........
开发者ID:adoggie,项目名称:TCE,代码行数:103,代码来源:conn_qpid.py

示例7: __init__

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import session [as 别名]
    def __init__(self, serviceURL, serviceAddress=None, serviceName=None,
                 conn=None, workers=3):
        self.__URL = url = parseURL(serviceURL)
        self.__serviceURL = serviceURL
        self.__serviceName = serviceName
        self.__serviceAddress = serviceAddress
        self.__workers = workers
        domain = url['path']

        # Prepare AMQP connection if not already there
        if not conn:
            conn = Connection(url['url'], transport=url['transport'], reconnect=True)
            conn.open()
            AMQPServiceProxy.domain= domain

            # Prefill __serviceAddress correctly if domain is given
            if AMQPServiceProxy.domain:
                self.__serviceAddress = '%s.command.core' % AMQPServiceProxy.domain

            if not self.__serviceAddress:
                raise AMQPException("no serviceAddress or domain specified")

            try:
                AMQPServiceProxy.worker[self.__serviceAddress]
            except KeyError:
                AMQPServiceProxy.worker[self.__serviceAddress] = {}

            # Pre instanciate core sessions
            for i in range(0, workers):
                ssn = conn.session(str(uuid4()))
                AMQPServiceProxy.worker[self.__serviceAddress][i] = {
                        'ssn': ssn,
                        'sender': ssn.sender(self.__serviceAddress),
                        'receiver': ssn.receiver('reply-%s; {create:always, delete:always, node: { type: queue, durable: False, x-declare: { exclusive: False, auto-delete: True } }}' % ssn.name),
                        'locked': False}

        # Store connection
        self.__conn = conn
        self.__ssn = None
        self.__sender = None
        self.__receiver = None
        self.__worker = None

        # Retrieve methods
        try:
            AMQPServiceProxy.methods
        except AttributeError:
            AMQPServiceProxy.methods = None
            AMQPServiceProxy.methods = {}

        # Retrieve methods
        try:
            AMQPServiceProxy.methods[self.__serviceAddress]
        except KeyError:
            AMQPServiceProxy.methods[self.__serviceAddress] = None
            AMQPServiceProxy.methods[self.__serviceAddress] = self.getMethods()

            # If we've no direct queue, we need to push to different queues
            if AMQPServiceProxy.domain:
                queues = set([
                        x['target'] for x in AMQPServiceProxy.methods[self.__serviceAddress].itervalues()
                        if x['target'] != 'core'
                    ])

                # Pre instanciate queue sessions
                for queue in queues:
                    for i in range(0, workers):
                        ssn = conn.session(str(uuid4()))
                        AMQPServiceProxy.worker[queue] = {}
                        AMQPServiceProxy.worker[queue][i] = {
                                'ssn': ssn,
                                'sender': ssn.sender("%s.command.%s" %
                                    (AMQPServiceProxy.domain, queue)),
                                'receiver': ssn.receiver('reply-%s; {create:always, delete:always, node: { type: queue, durable: False, x-declare: { exclusive: False, auto-delete: True } }}' % ssn.name),
                                'locked': False}
开发者ID:lhm-limux,项目名称:gosa,代码行数:77,代码来源:amqp_proxy.py


注:本文中的qpid.messaging.Connection.session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。