Discussion of Jprotobuf-rpc-socket - the Yinhao Min's blog

Baidu discussion of Jprotobuf-rpc-socket together to open a Post

Background note

Consider the internal stability of multi-system interaction, we generally use the RPC framework to interact, I used Baidu development in Baidu Jprotobuf-rpc-socket , here is the User Guide .
While Baidu's open source framework, but the market with too little, leading to information posted and tutorials, and more experience are too little, accumulated since the beginning of the desired use Jprotobuf-rpc-socket of experience and course materials. This is my finishing Jprotobuf-rpc-Demo , which has detailed instructions for use.

Question 1: Objects can not support Proxy service publishing

When we publish a proxy class, the problem will appear in the following code.

com.baidu.jprotobuf.pbrpc.server.RpcServiceRegistry

    /**
     * Register service.
     *
     * @param target the target
     */
    public void registerService(final Object target) {
        if (target == null) {
            throw new IllegalArgumentException("Param 'target' is null.");
        }
        Class<? extends Object> cls = target.getClass();
        ReflectionUtils.doWithMethods(cls, new ReflectionUtils.MethodCallback() {
            public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                ProtobufRPCService protobufPRCService = method.getAnnotation(ProtobufRPCService.class);
                if (protobufPRCService != null) {
                    doRegiterService(method, target, protobufPRCService);
                }
            }
        });
    }

At runtime, the following code to get the class "class com.sun.proxy. $ Proxy81".

Class<? extends Object> cls = target.getClass();

This results in the following statement, we can not get methods that require registration.

ProtobufRPCService protobufPRCService = method.getAnnotation(ProtobufRPCService.class);

Our implementation code is this.

@Slf4j
@RpcExporter(port = "1033", rpcServerOptionsBeanName = "rpcServerOptions")
@Service(DemoConstants.PMP_SERVICE)
public class PmpServiceImpl implements PmpService {

    @Autowired
    private HelloWorldRunService helloWorldRunService;

    @ProtobufRPCService(serviceName = DemoConstants.PMP_SERVICE, methodName = "helloWorld")
    @Override
    public HelloWorldResponse helloWorld(HelloWorldRequest request) {
        log.info("Called by request:" + request);
        HelloWorldResponse response = helloWorldRunService.helloWorld(request);
        return response;
    }

}

In fact, we can use the following code to get the proxy class, the developers do not know whether there are other considerations of this matter?

public static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {  
    InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy);  
    Object target = ((AdvisedSupport) ReflectionUtils.getFieldValue(invocationHandler,"advised")).getTargetSource().getTarget();  
    return target;  
}  


Original: Large columns  discussion of Jprotobuf-rpc-socket - the Yinhao Min's blog


Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11618342.html