Dubbo Interface Test Study Notes

About dubbo:

  A framework for distributed remote service call, call transfer protocols and agreements typically contain a sequence of protocol. Dubbo itself supports a variety of remote invocation, such as Dubbo RPC (binary serialization + tcp protocol), http invoker (binary serialization + http protocol), hessian (a binary serialization + http protocol), WebServices (text serialization + http protocol )Wait.

Official website address

Node Role Description
node Role Description
Provider Expose service provider service
Consumer Call the remote service consumer services
Registry Service registration and discovery registries
Monitor The number of calls statistics monitoring center services and call time
Container Run container services
Call relationship Description
  1. Responsible for starting the service container, load, run service provider.
  2. Service provider when you start, registration services they provided to the registry.
  3. Consumer services at startup, you need to subscribe to the service registry.
  4. Registry return address list service providers to consumers, if there is a change, the registry will be based on long push to change the data connection to the consumer.
  5. Service consumers, providers from the list of addresses, soft load balancing algorithm, choose a provider call, if the call fails, then select another call.
  6. Service consumers and providers, in memory of the cumulative number of calls and call time, time sent once per minute statistical data to the monitoring center.

 

How to test dubbo Interface:

Python hessian + http way call:

1, dubbo projects, increase hessian way serialization, and its dependencies. The following figure shows an example of xml configuration.

Official configuration hessian protocol and rely examples

Official multi-protocol configuration examples

 

2. Get Interface address (can be viewed in the monitoring and management center), into the reference methods and approaches.

 

3, mounting python-hessian

python -m pip install python-hessian

 

4, Python scripting Call Interface

1  # coding=utf-8
2  from pyhessian.client import HessianProxy
3  url = "http://169.254.210.145:1234/com.ymxdclass.user.service.UserService" 
4  params = u"什么我调用成功了吗"
  # 创建连接对象 5 service = HessianProxy(full_url)
  # 调用方法(重载方法__main__()里发送二进制数据请求,进行调用)
6 res = service.sayHello(params) 7 print(res)

pyhessian官方调用例子

 

java调用脚本

 1 import com.ymxdclass.user.service.UserService;
 2 import org.junit.BeforeClass;
 3 import org.junit.Test;
 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
 5 
 6 public class ConsumerTest {
 7     static ClassPathXmlApplicationContext context;
 8     static UserService userService;
 9     @BeforeClass
10     public static void beforeClass(){
11         if(context==null) {
12             // 默认从类路径中加载配置文件
13             context = new ClassPathXmlApplicationContext("consumer.xml");
14             System.out.println("load");
15             // 在Spring中还提供了Lifecycle接口,Lifecycle中包含start/stop方法,实现此接口后Spring保证在启动的时候调用其start方法开始生命周期,主要用于控制异步处理过程
16            context.start();
17 //            System.out.println("start");
18         }
       // 创建接口实例(定义接口的引用变量,再引用实现了该接口的实例)
19 userService=(UserService) context.getBean("userService"); 20 21 } 22 @Test 23 public void consumerTestCase1(){
       // 调用方法
24 String hello = userService.sayHello("world"); 25 System.out.println("result: " ); 26 System.out.println(userService.sayHello("yummy ")); 27 } 28 29 }

 

Guess you like

Origin www.cnblogs.com/minerrr/p/10932465.html