Comments (4)
@shangjiuliu 目前还不支持,可以近期支持。
from starlight.
@wenweihu86 请问泛化调用支持了吗,有计划什么时候支持吗?
from starlight.
@shangjiuliu 目前还不支持,可以近期支持。
请问支持了么
from starlight.
I hope it can be used in this way.
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)
- Why NShead protocol can't coexistence with other protocols
- 请问下rpc server端能支持返回空对象吗 HOT 1
- bug fix of hulu protocol attachment
- brpc-java RpcServer.shutdown()报错 HOT 1
- com.baidu.brpc.naming.HealthyCheckTimer 健康检查逻辑问题
- 这是什么代码?
- Java brpc client 如何获取 远端的ip port HOT 2
- HealthyCheckTimer 发现可用机器列表bug,如果机器重启,roundRobin会导致流量分配不均
- 怎么支持广播
- 问下brpc-java有计划捐给apache吗?
- 请问brpc-java不支持一致性hash负载均衡策略吗? HOT 1
- BaiduRpcProtocol第102行,会产生ClassCastException HOT 2
- DEMO信息缺失、勘误和问题请教
- 请教DEMO相关问题 HOT 2
- 有计划支持RDMA吗 HOT 2
- 现在的版本不支持JDK17吗 HOT 1
- com.baidu.cloud:spring-cloud-baidu-thirdparty-commons:jar:2022.2.0 与 Netty Epoll 冲突 HOT 3
- can increase the network usage for reading data from cpp server by java client HOT 2
- Java版本支持streaming HOT 1
- BaiduBrpcProtocol 协议存在bytebuf over release 问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from starlight.