开源软件名称:r3
开源软件地址:https://gitee.com/zhoufn/r3
开源软件介绍:
R3 FRAMEWORK - 分布式实时处理框架简介基于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; }} Worker端 <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> Leader端 <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> 配置属性@Out 接口配置注解类,应用于API接口上,用于参数分流。 Attribute | Description |
---|
value | 用户自定义参数分流类,需要继承自r3.flow.OutHandler |
@In 接口配置注解类,应用于API接口上,用于参数合流 Attribute | Description |
---|
value | 用户自定义参数合流类,需要继承自r3.flow.InHandler |
r3:application 应用配置<r3:application name="worker-1" host="localhost" port="20080"></r3:application>
Attribute | Description |
---|
name | 应用名称,必须项,同名的application为同组,组内软负载取其一。 | host | 监听地址,默认为“AUTO”,如果为“AUTO”的话,会自动采用本机IP地址。多网卡的情况下可以手动设置IP。 | port | 监听端口,默认为20080。 |
r3:registry 注册中心配置<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 工作者配置<r3:worker id="sayHelloWorker" ref="SayHelloServiceImpl" interface="r3.example.api.SayHelloService">
Attribute | Description |
---|
id | spring bean id。 | ref | 引用的spring的bean。 | interface | 实现的接口类。 |
r3:leader 代理者配置<r3:leader id="sayHelloServiceImpl" interface="r3.example.api.SayHelloService"></r3:leader>
Attribute | Description |
---|
id | spring bean id。 | interface | 代理的接口类。 | loadbalance | 负载策略,默认为“random”,尚不支持其他策略。 |
版本说明采用行星名称命名。 后续开发计划- 引入Filter概念,提供r3-filter模块。
- 引入leader的超时和重试机制。
- 提供其他的LoadBalance策略。
|
请发表评论