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


Python TornadoConnection.set_backpressure_multiplier方法代码示例

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


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

示例1: Tester

# 需要导入模块: from pika.adapters.tornado_connection import TornadoConnection [as 别名]
# 或者: from pika.adapters.tornado_connection.TornadoConnection import set_backpressure_multiplier [as 别名]
class Tester(object):
	def __init__(self,queue,exchange,host='localhost',port=5672):
		user1 = User(1,1)
		user2 = User(2,2)
		user3 = User(3,3)
		self.queue = queue
		self.exchange =exchange
		self.users = [user1]#,user2,user3]
		self.pKeys = {}
		self.boundQueue = 0

	def on_queue_bound(self, frame):
		self.boundQueue -= 1
		print "BOUND",self.boundQueue
		if self.boundQueue == 0:
			print "Start consume!!"
			self.channel.basic_consume(consumer_callback=self.on_message, queue=self.queue, no_ack=True)
		else:
			return

		for user in self.users:
			self.channel.basic_publish(exchange='dealer_exchange_1',
								routing_key="dealer",
								body=json.dumps({'method':'enter','source':'IAMGOD', "room_id":1, "user_id":user.user_id}))

		self.channel.basic_publish(exchange='dealer_exchange_1',
								routing_key="dealer",
								body=json.dumps({'method':'sit','source':'IAMGOD','user_id':1, "room_id":1, "seat":1,"private_key":self.users[0].private_key, "stake":100}))

#		self.channel.basic_publish(exchange='dealer_exchange_1',
#								routing_key="dealer",
#								body=json.dumps({'method':'sit','source':'IAMGOD','user_id':2, "room_id":1, "seat":2,"private_key":self.users[1].private_key, "stake":100}))
#
#		self.channel.basic_publish(exchange='dealer_exchange_1',
#								routing_key="dealer",
#								body=json.dumps({'method':'sit','source':'IAMGOD','user_id':3, "room_id":1, "seat":3,"private_key":self.users[2].private_key, "stake":500}))

	def on_queue_declared(self, frame):
		for user in self.users:
			self.boundQueue += 1
			self.channel.queue_bind(exchange='dealer_exchange_1',
						queue=self.queue,routing_key=user.private_key,
						callback=self.on_queue_bound
					)


		self.boundQueue += 1
		self.channel.queue_bind(exchange='dealer_exchange_1',
				queue=self.queue,routing_key="IAMGOD",
				callback=self.on_queue_bound
				)

		broadcast_key  = "broadcast_%s_%d.testing" % ( exchange, room_id)

		self.boundQueue += 1
		self.channel.queue_bind(exchange='dealer_exchange_1',
				queue=self.queue,routing_key=broadcast_key,
				callback=self.on_queue_bound
				)


	def on_exchange_declared(self,frame):
		self.channel.queue_declare(queue    = self.queue,
				auto_delete = True,
				durable     = True,
				exclusive   = False,
				callback=self.on_queue_declared,
				arguments = {"x-expires":15000})


	def on_channel_open(self,channel):
		self.channel    = channel
		self.channel.exchange_declare(exchange = self.exchange,
				type        = 'topic',
				auto_delete = True,
				durable     = False,
				callback=self.on_exchange_declared
				)

	def on_connected(self,connection):
		connection.channel(self.on_channel_open)

	def start(self):
		credentials = pika.PlainCredentials('guest', 'guest')
		param = pika.ConnectionParameters(host="localhost",
						port=5672,
						virtual_host="/",
						credentials=credentials)

		self.connection = TornadoConnection(param, on_open_callback=self.on_connected)
		self.connection.set_backpressure_multiplier(100000)
	def on_message(self,ch, method, properties, body):
		print " [x] %r:%r" % (method.routing_key, json.loads(body),)
		msg = json.loads(body)
#		if 'Cards in hand' in msg:
		self.pKeys[method.routing_key] = 1
#
		if len(self.pKeys) == 1:
			self.pKeys = {}
			self.channel.basic_publish(exchange='dealer_exchange_1',
#.........这里部分代码省略.........
开发者ID:hackur,项目名称:HTML5-Texas-Hold-em-,代码行数:103,代码来源:send.py

示例2: Dealer

# 需要导入模块: from pika.adapters.tornado_connection import TornadoConnection [as 别名]
# 或者: from pika.adapters.tornado_connection.TornadoConnection import set_backpressure_multiplier [as 别名]
class Dealer(object):
	def __init__(self,exchange,host,port):
		self.exchange   = exchange
		self.host       = host
		self.port       = port
		self.room_list  = {}


	def init_database(self):
		database.init_database()

		info =	DealerInfo.find(exchange = self.exchange)

		if not info:
			info = DealerInfo.new(self.exchange)
		else:
			print "WARNING, dealer %s already in database" % self.exchange


		info.rooms = 0
		self.info = info

	def on_queue_bound(self, frame):
		self.channel.basic_consume(
				consumer_callback=self.on_message,
				queue=self.queue_name, no_ack=True)


	def on_queue_declared(self, frame):
		self.queue_name = frame.method.queue
		self.channel.queue_bind(
				exchange    = self.exchange,
				queue       = self.queue_name,
				routing_key = 'dealer',
				callback=self.on_queue_bound)


	def on_exchange_declared(self,frame):
		self.channel.queue_declare(
				auto_delete = True,
				durable     = False,
				exclusive   = False,
				callback	=	self.on_queue_declared)


	def on_channel_open(self,channel):
		self.channel    = channel
		self.channel.exchange_declare(exchange = self.exchange,
				type        = 'topic',
				auto_delete = True,
				durable     = False,
				callback=self.on_exchange_declared
				)

	def on_connected(self,connection):
		connection.channel(self.on_channel_open)

	def start(self):
		credentials = pika.PlainCredentials('guest', 'guest')
		param = pika.ConnectionParameters(self.host,
						port=self.port,
						virtual_host="/",
						credentials=credentials)

		self.connection = TornadoConnection(param, on_open_callback=self.on_connected)
		self.connection.set_backpressure_multiplier(100000)

	def cmd_action(self, args):
		print "action in dealer %d" % args["action"]
		if args["room_id"] in self.room_list:
			current_room    = self.room_list[args["room_id"]]
			current_room.user_action(args)

	def cmd_chat(self, args):
		print args
		room	= self.room_list[args['room']]
		room.chat(args['user'], args['seat'], args['content'])

	def cmd_sit(self, args):
		print "sit received"
		source			= args['source']
		private_key		= args['private_key']
		stake			= args['stake']
		user			= User.find(_id=args['user_id'])
		print args['user_id']
		current_room	= self.room_list[args["room_id"]]
		(status, msg)	= current_room.sit(user, int(args["seat"]), source, private_key,stake)

		if status:
			message	= {"status": "success" }
		else:
			message = {"status": "failed", "msg": msg}
		self.channel.basic_publish( exchange    = self.exchange,
									routing_key = source,
									body        = json.dumps(message))

	def broadcast(self, routing_key, msg):
		self.channel.basic_publish(	exchange	= self.exchange,
									routing_key	= routing_key,
									body		= json.dumps(msg))
#.........这里部分代码省略.........
开发者ID:hackur,项目名称:HTML5-Texas-Hold-em-,代码行数:103,代码来源:dealer.py


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