由于用例比较简单,直接上代码吧!
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=0 OK=1 OK=2 OK=3 OK=4 OK=5 OK=6 OK=7 OK=8 OK=9
时间: 2024-11-10 08:51:28