Beispiel #1
0
 def start(self):
     # 创建RbbitMQ连接
     self.conn = rpc.create_connection()
     # 创建分发器
     rpc_dispatcher = dispatcher.RpcDispatcher(self.manager)
     # 创建主题消费者
     self.conn.create_consumer(self.topic, rpc_dispatcher)
     # 激活主题消费者
     self.conn.consume()
Beispiel #2
0
def call(topic, msg, timeout):
    print('Making synchronous call on %s ...\n' % topic)
    msg_id = DIRECT + str(uuid.uuid4())
    msg.update({'msg_id': msg_id})
    print('MSG_ID is %s\n' % msg_id)

    conn = rpc.create_connection()
    wait_msg = CallWaiter(conn)
    conn.declare_direct_consumer(msg_id, wait_msg)
    conn.topic_send(topic, msg)
    return wait_msg.wait_reply()
Beispiel #3
0
def call(topic, msg, timeout):
    print('Making synchronous call on %s ...\n' % topic)
    msg_id = DIRECT + str(uuid.uuid4())                # 构造消息ID
    msg.update({'msg_id': msg_id})                     # 将消息ID添加到消息体中
    print('MSG_ID is %s\n' % msg_id)

    conn = rpc.create_connection()                     # 连接RabbitMQ服务器
    wait_msg = CallWaiter(conn)                        # CallWaiter对象是直接消费者的处理方法
    conn.declare_direct_consumer(msg_id, wait_msg)     # 声明直接交换器
    conn.topic_send(topic, msg)                        # 等待RPC响应
    return wait_msg.wait_reply()
Beispiel #4
0
def call(topic,msg,timeout):
	print('Making synchronous call on %s ...\n' % topic)
	msg_id=DIRECT+str(uuid.uuid4())
	msg.update({'msg_id':msg_id})
	print('MSG_ID is %s\n' % msg_id)

	conn=rpc.create_connection()
	wait_msg=CallWaiter(conn)
	conn.declare_direct_consumer(msg_id,wait_msg)
	conn.topic_send(topic,msg)
	return wait_msg.wait_reply()
def call(topic, msg, timeout):
    print('Making synchronous call on %s ...\n' % topic)
    msg_id = DIRECT + str(uuid.uuid4())
    msg.update({'msg_id': msg_id})
    print('MSG_ID is %s\n' % msg_id)

    conn = rpc.create_connection() 
    wait_msg = CallWaiter(conn)
    conn.declare_direct_consumer(msg_id, wait_msg)
    conn.topic_send(topic, msg)
    # 调用完send之后,在rabbitmq中
    # queue只有1条
    # feedback_request_4d3bb5ea-9cc5-4b67-980e-57f12b59a59a
    # exchange有2条
    # feedback_request_4d3bb5ea-9cc5-4b67-980e-57f12b59a59a
    # sendout_request

    # 为什么返回的是回调函数???
    # 其实就是调用 consume方法,阻塞,接收 feedback_request_4d3bb5ea-9cc5-4b67-980e-57f12b59a59a 中的数据
    return wait_msg.wait_reply()
 def start(self):
     self.conn = rpc.create_connection()
     rpc_dispatcher = dispatcher.RpcDispatcher(self.manager)
     self.conn.create_consumer(self.topic, rpc_dispatcher)
     self.conn.consume()