Linkerd——本地运行完整案例

参考 Linkerd起步——之本地运行

我们做如下变更:

服务端把index.html变为response.json


{"name":"James","nation":"china","msg":"Hello World."}

增加一个自动的客户端请求request.py


import urllib
import urllib.request as urllib2
import requests
import threading,time

class SendRequest(threading.Thread):
  def __init__(self,interval,count):
    threading.Thread.__init__(self)
    self.interval = interval
    self.count = count
  def run(self):
    try:
      url = "http://localhost:4140/response.json"
      # 注意这是服务名
      headers={"Host":"web"}
      result = requests.get(url,headers=headers)
      print(time.strftime('%Y-%m-%d %X',time.localtime())+" - "+str(self.count)+" - "+result.text)
      self.count = self.count+1
      #time.sleep(1)
    except Exception as e:
      print(e)
    finally:
      SendRequest(self.interval,self.count).start()

if __name__ == '__main__':
  count = 1
  SendRequest(0.1,count).start()

运行请求客户端:

$ python request.py

运行图如下:

火狐截图_2017-12-26T07-53-45.248Z.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容