代码拉取完成,页面将自动刷新
基于Spring的分布式实时处理框架。
public interface SayHelloService {
@Out(SayHelloOutHandler.class)
@In(SayHelloInHandler.class)
List<String> sayHello(List<String> names);
}
public class SayHelloOutHandler extends OutHandler {
@Override
public List<Object[]> shard(Object[] parameters, int shardCount) throws Throwable {
List<Object[]> result = new ArrayList<>();
List<String> param = (List<String>) parameters[0];
int perSize = param.size() / shardCount;
for(int i=0;i<shardCount;i++){
result.add(new Object[]{param.subList(i*perSize,(i!=shardCount-1?(i+1)*perSize:param.size()))});
}
return result;
}
}
public class SayHelloInHandler extends InHandler {
@Override
public Object join(Object[] results) throws Throwable {
List<String> list = new ArrayList<>();
for(Object object : results){
list.addAll((List<String>)object);
}
return list;
}
}
public class SayHelloServiceImpl implements SayHelloService {
@Override
public List<String> sayHello(List<String> names) {
List<String> newNames = new ArrayList<>();
for (String name : names) {
String newName = "hello " + name;
newNames.add(newName);
}
return newNames;
}
}
<r3:application name="worker-1" host="AUTO" port="20080"></r3:application>
<r3:registry address="localhost:2181" namespace="r3"></r3:registry>
<r3:worker id="sayHelloWorker" ref="sayHelloServiceImpl" interface="r3.example.api.SayHelloService"></r3:worker>
<bean id="sayHelloServiceImpl" class="r3.example.worker.SayHelloServiceImpl" scope="prototype"></bean>
<r3:application name="leader-one" ></r3:application>
<r3:registry address="localhost:2181" namespace="r3"></r3:registry>
<r3:leader id="sayHelloServiceImpl" interface="r3.example.api.SayHelloService"></r3:leader>
注解类,应用于API接口上,用于参数分流。
Attribute | Description |
---|---|
value | 用户自定义参数分流类,需要继承自r3.flow.OutHandler |
注解类,应用于API接口上,用于参数合流
Attribute | Description |
---|---|
value | 用户自定义参数合流类,需要继承自r3.flow.InHandler |
<r3:application name="worker-1" host="localhost" port="20080"></r3:application>
Attribute | Description |
---|---|
name | 应用名称,必须项,同名的application为同组,组内软负载取其一。 |
host | 监听地址,默认为“AUTO”,如果为“AUTO”的话,会自动采用本机IP地址。多网卡的情况下可以手动设置IP。 |
port | 监听端口,默认为20080。 |
<r3:registry address="localhost:2181" namespace="r3"></r3:registry>
Attribute | Description |
---|---|
address | 注册中心zookeeper的地址,默认为“localhost:2181”。 |
namespace | 应用注册的命名空间,zookeeper的根节点,默认为:r3。 |
sessionTimeout | 回话超时时间设置,单位为毫秒,默认为3000。 |
connectionTimeout | 连接的超时时间,单位为毫秒,默认为3000。 |
interval | 多次尝试注册服务的时间间隔,单位为毫秒,默认为30000。 |
<r3:worker id="sayHelloWorker" ref="SayHelloServiceImpl" interface="r3.example.api.SayHelloService">
Attribute | Description |
---|---|
id | spring bean id。 |
ref | 引用的spring的bean。 |
interface | 实现的接口类。 |
<r3:leader id="sayHelloServiceImpl" interface="r3.example.api.SayHelloService"></r3:leader>
Attribute | Description |
---|---|
id | spring bean id。 |
interface | 代理的接口类。 |
loadbalance | 负载策略,默认为“random”,尚不支持其他策略。 |
采用行星名称命名。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。