• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

r3: R3 FRAMEWORK - 分布式实时处理框架

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

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接口上,用于参数分流。

AttributeDescription
value用户自定义参数分流类,需要继承自r3.flow.OutHandler

@In 接口配置

注解类,应用于API接口上,用于参数合流

AttributeDescription
value用户自定义参数合流类,需要继承自r3.flow.InHandler

r3:application 应用配置

<r3:application name="worker-1" host="localhost" port="20080"></r3:application>

AttributeDescription
name应用名称,必须项,同名的application为同组,组内软负载取其一。
host监听地址,默认为“AUTO”,如果为“AUTO”的话,会自动采用本机IP地址。多网卡的情况下可以手动设置IP。
port监听端口,默认为20080。

r3:registry 注册中心配置

<r3:registry address="localhost:2181" namespace="r3"></r3:registry>

AttributeDescription
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">

AttributeDescription
idspring bean id。
ref引用的spring的bean。
interface实现的接口类。

r3:leader 代理者配置

<r3:leader id="sayHelloServiceImpl" interface="r3.example.api.SayHelloService"></r3:leader>

AttributeDescription
idspring bean id。
interface代理的接口类。
loadbalance负载策略,默认为“random”,尚不支持其他策略。

版本说明

采用行星名称命名。

后续开发计划

  1. 引入Filter概念,提供r3-filter模块。
  2. 引入leader的超时和重试机制。
  3. 提供其他的LoadBalance策略。

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap