本文主要介紹使用python
呼叫hession協議dubbo
介面示例。
關於dubbo hession協議:
dubbo本身支援多種遠端呼叫方式,例如dubbo rpc(二進位制序列化 + tcp協議)、http invoker(二進位制序列化 + http協議)、hessian
(二進位制序列化 + http協議)、webservices (文字序列化 + http協議)等。
dubbo將這些協議的實現進行了封裝了,無論是服務端(開發服務)還是客戶端(呼叫服務),都不需要關心協議的細節,只需要在配置中指定使用的協議即可,從而保證了服務提供方與服務消費方之間的透明。
如果我們使用dubbo的服務註冊中心元件,這樣服務提供方將服務發布到註冊的中心,只是將服務的名稱暴露給外部,而服務消費方只需要知道註冊中心和服務提供方提供的服務名稱,就能夠透明地呼叫服務。
python
呼叫hession協議介面基本流程如下:
hessian,或者pip install python-hessian進行安裝
2. 定義hession介面的服務、介面、方法名稱
3. 使用protocol.object_factory方法,呼叫該方法引數構造方法,構造呼叫引數
4. 使用hessianproxy方法,呼叫介面
示例**:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding:utf-8 -*-
from pyhessian.client import hessianproxy
from pyhessian import protocol
import json
def invokehessian(service,inte***ce,method,req,retcode='000000'):
try:
url=''+service+'.'+inte***ce
print 'url:\t%s'%url
print 'method:\t%s'%method
print 'req:\t%s'%req
res=getattr(hessianproxy(url),method)(req)
print 'res:\t%s'%json.dumps(res,ensure_ascii=false)
except exception,e:
print e
if __name__ == '__main__':
service='com.service.common.api.service'
inte***ce='testhessianservice'
method='testhessian'
req=protocol.object_factory('com.service.common.api.service.model.req.testhessianrequest',
param1='lovesoo',param2=10086)
invokehessian(service, inte***ce, method,req)
介面測試 dubbo 介面測試技術
dubbo是阿里巴巴開源的一套rpc方案,以為理念很契合微服務,這幾年很火,使用者裡面不凡京東,噹噹,去哪兒等大公司。rpc場景 dubbo架構 官網也提供了乙個很簡單實用的demo來演示dubbo協議的使用,用起來的確很簡單強大。可參考 首頁的例子已經很好了。任何乙個dubbo服務都支援乙個簡單的...
jMeter測試dubbo介面
1.建立執行緒組,新增dubbo請求。填寫zookeeper位址,如果有多個,可以用 隔開 2.get provider list獲取所有的介面列表 3.選擇介面和對應的方法 4.填寫引數名稱和值 1.建立執行緒組,新增dubbo請求 2.填寫直連位址 3.填寫介面和方法名 4.填寫引數 看完點贊 ...
使用jmeter 測試dubbo介面
1 打包dubbo介面以及相關依賴 3 將dubbo介面 依賴 jmeter dubbo 外掛程式一起放在jmeter 的 lib ext 目錄下 4 避免亂碼問題 jmeter 預設是 ios 8859 1 修改 jmeter bin jmeter.properties 這個檔案,增加 sampl...