<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1. client ~~~ __author__ = 'dailin' import pika import uuid class FibonacciRpcClient(object): def __init__(self): credentials = pika.PlainCredentials('tuna', 'tuna') self.connection = pika.BlockingConnection(pika.ConnectionParameters( host='192.168.56.130', credentials=credentials )) self.channel = self.connection.channel() # 不指定queue名字,rabbit會隨機分配一個名字,exclusive=True會在使用此queue的消費者斷開后,自動將queue刪除 result = self.channel.queue_declare(exclusive=True) self.callback_queue = result.method.queue # 隨機生成一個名字 self.channel.basic_consume(self.on_response, no_ack=True, # 聲明消費 queue=self.callback_queue) def on_response(self, ch, method, props, body): if self.corr_id == props.correlation_id: self.response = body ''' 向server端發送命令,然后不斷的調用消費server端返回的隊列 ''' def call(self, n): self.response = None self.corr_id = str(uuid.uuid4()) # 生成任務的唯一標識,確保client與server之間任務的唯一性 self.channel.basic_publish(exchange='', routing_key='rpc_queue', properties=pika.BasicProperties( reply_to=self.callback_queue, # 回調隊列 correlation_id=self.corr_id, ), body=str(n)) while self.response is None: self.connection.process_data_events() # 非阻塞調用consume,server端發來的消息 return int(self.response) fibonacci_rpc = FibonacciRpcClient() print(" [x] Requesting fib(30)") response = fibonacci_rpc.call(30) print(" [.] Got %r" % response) ~~~ 2. server ~~~ __author__ = 'dailin' import pika import time credentials = pika.PlainCredentials('tuna', 'tuna') connection = pika.BlockingConnection(pika.ConnectionParameters( host='192.168.56.130', credentials=credentials )) channel = connection.channel() channel.queue_declare(queue='rpc_queue') # 客戶端隊列 def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n - 1) + fib(n - 2) def on_request(ch, method, props, body): n = int(body) print(" [.] fib(%s)" % n) response = fib(n) # 給客戶端返回結果 ch.basic_publish(exchange='', routing_key=props.reply_to, # 客戶端發來的參數(指定server端回應消息的隊列) properties=pika.BasicProperties(correlation_id= \ props.correlation_id), body=str(response)) ch.basic_ack(delivery_tag=method.delivery_tag) channel.basic_qos(prefetch_count=1) channel.basic_consume(on_request, queue='rpc_queue') print(" [x] Awaiting RPC requests") while True: print("waitting for commands.....") connection.process_data_events() # 和channel.start_consuming()作用一樣都是消費,只不過是非阻塞 time.sleep(1) ~~~ connection.process_data_events() # 和channel.start_consuming()作用一樣都是消費,只不過是非阻塞 channel.start_consuming():會一直阻塞的循環消費 connection.process_data_events() # 非阻塞消費,沒有消息就過
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看