由于用例比较简单,直接上代码吧!
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.alibaba.dubbo.demo.DemoService;import com.alibaba.dubbo.rpc.service.EchoService;public class Consumer { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "classpath:consumer.xml" }); context.start(); // 回声测试 DemoService demoService = (DemoService) context.getBean("demoService"); for (int i = 0; i < 10; i++) { EchoService echoService = (EchoService) demoService; // 强制转型为EchoService String status = (String) echoService.$echo("OK=" + i); // 回声测试可用性 System.out.println(status); } }}
客户端控制台返回值:
OK=0OK=1OK=2OK=3OK=4OK=5OK=6OK=7OK=8OK=9