Giter Club home page Giter Club logo

Comments (4)

wenweihu86 avatar wenweihu86 commented on May 21, 2024

@shangjiuliu 目前还不支持,可以近期支持。

from starlight.

shawn-deng avatar shawn-deng commented on May 21, 2024

@wenweihu86 请问泛化调用支持了吗,有计划什么时候支持吗?

from starlight.

YK-Leung avatar YK-Leung commented on May 21, 2024

@shangjiuliu 目前还不支持,可以近期支持。

请问支持了么

from starlight.

loongs-zhang avatar loongs-zhang commented on May 21, 2024

I hope it can be used in this way.

server: https://github.com/baidu/brpc-java/blob/master/brpc-java-examples/brpc-java-core-examples/src/main/java/com/baidu/brpc/example/jprotobuf/RpcServerTest.java

GenericService

public interface GenericService {
    
    Object $invoke(String serviceName, String methodName, String[] parameterTypes, Object[] args) throws RuntimeException;
    
    Future<Object> $invokeAsync(String serviceName, String methodName, String[] parameterTypes, Object[] args) throws RuntimeException;
}

generic call client

public class RpcClientTest {
    
    public static void main(String[] args) {
        RpcClientOptions clientOption = new RpcClientOptions();
        clientOption.setProtocolType(Options.ProtocolType.PROTOCOL_BAIDU_STD_VALUE);
        clientOption.setWriteTimeoutMillis(1000);
        clientOption.setReadTimeoutMillis(1000);
        clientOption.setMaxTotalConnections(1000);
        clientOption.setMinIdleConnections(10);
//        clientOption.setIoThreadNum(40);
        clientOption.setLoadBalanceType(LoadBalanceStrategy.LOAD_BALANCE_FAIR);
        clientOption.setCompressType(Options.CompressType.COMPRESS_TYPE_NONE);
        
        String serviceUrl = "list://127.0.0.1:8002";
        if (args.length == 1) {
            serviceUrl = args[0];
        }
        
        List<Interceptor> interceptors = new ArrayList<Interceptor>();
        interceptors.add(new CustomInterceptor());
        
        // build request
        Map<String, Object> request = new HashMap<>();
        request.put("message", "hellooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
        
        // async call
        RpcClient rpcClient = new RpcClient(serviceUrl, clientOption, interceptors);
        RpcCallback<EchoResponse> callback = new RpcCallback<EchoResponse>() {
            @Override
            public void success(EchoResponse response) {
                if (response != null) {
                    System.out.printf("async call EchoService.echo success, response=%s\n",
                            response.getMessage());
                } else {
                    System.out.println("async call failed, service=EchoService.echo");
                }
            }
            
            @Override
            public void fail(Throwable e) {
                System.out.printf("async call EchoService.echo failed, %s\n", e.getMessage());
            }
        };
        GenericService asyncEchoService = BrpcProxy.getProxy(rpcClient, GenericService.class);
        try {
            Future<Object> future = asyncEchoService.$invokeAsync("com.baidu.brpc.example.jprotobuf.EchoServiceAsync",
                    "echo",
                    new String[]{"com.baidu.brpc.example.jprotobuf.EchoRequest", "com.baidu.brpc.client.RpcCallback"},
                    new Object[]{request, callback});
            try {
                if (future != null) {
                    future.get();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } catch (RpcException ex) {
            System.out.println("rpc send failed, ex=" + ex.getMessage());
        }
        rpcClient.stop();
        System.out.println("brpc client finished...");
    }
    
}

from starlight.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.