DemoRpc.java 1.1 KB
Newer Older
武汉红喜's avatar
武汉红喜 已提交
1
package org.hongxi.whatsmars.dubbo.demo.consumer.rpc;
武汉红喜's avatar
武汉红喜 已提交
2 3

import com.alibaba.dubbo.config.annotation.Reference;
武汉红喜's avatar
武汉红喜 已提交
4
import org.hongxi.whatsmars.dubbo.demo.api.DemoService;
武汉红喜's avatar
武汉红喜 已提交
5
import org.hongxi.whatsmars.dubbo.demo.api.OtherService;
武汉红喜's avatar
武汉红喜 已提交
6 7 8 9 10 11 12 13 14 15 16 17
import org.springframework.stereotype.Component;

/**
 * Created by javahongxi on 2017/12/4.
 * 将服务调用包装,可以方便进行调用监控
 */
@Component
public class DemoRpc {

    @Reference(version = "1.0.0")
    private DemoService demoService;

武汉红喜's avatar
武汉红喜 已提交
18
    @Reference(version = "1.0.0", registry = "otherRegistry")
武汉红喜's avatar
武汉红喜 已提交
19 20
    private OtherService otherService;

武汉红喜's avatar
武汉红喜 已提交
21 22 23 24 25 26 27 28 29 30
    public String sayHello(String name) {
        String result = null;
        try {
            result = demoService.sayHello(name);
        } catch (Exception e) {
            // log
            e.printStackTrace();
        }
        return result;
    }
武汉红喜's avatar
武汉红喜 已提交
31 32 33 34 35 36 37 38 39 40 41

    public String sayHello2(String name) {
        String result = null;
        try {
            result = otherService.sayHello(name);
        } catch (Exception e) {
            // log
            e.printStackTrace();
        }
        return result;
    }
武汉红喜's avatar
武汉红喜 已提交
42
}