storm DRPC指南
来源:互联网 发布:神策分析数据分析技术 编辑:程序博客网 时间:2024/06/06 06:52
- 一什么是DRPC
- 二LocalDPRC的例子
- 三RemoteDRPC将DPRC拓扑提交至集群
- 1启动DRPC服务器
- 2准备storm拓扑代码并提交
- 3使用客户端发起请求
(一)什么是DRPC
先看一个经典的图:
DRPC与一般的RPC没有区别,只不过它是分布式的。
对于用户而言,他是向一个DRPC服务器发送请求,然后等待DRPC的返回结果。整个流程如下:
1、用户向DRPC服务器发送请求,请求内容主要包括请求的方法名以及请求的参数。
2、DRPC服务器接收到这个请求后,将请求发送到拓扑的spout。
3、拓扑计算完成后,将结果返回到DRPC服务器。结果是以请求参数作为key,计算结果作为value的一个tuple(即有2个域)。
4、DRPC服务器将结果返回用户。
简单的说,就是用户的请求作为spout的数据源
对于高计算密度的RPC应用,DRPC可以将请求均匀的分布在整个storm集群进行计算。
在storm0.9以后,drpc都使用了trident的API来创建拓扑,不再使用原有API。
(二)LocalDPRC的例子
下面的例子中将一些字符串发送给DRPC服务器,然后经过拓扑的计算(在字符串后面加上一下“!”)返回到客户端。
public class LocalDRPCDemo { public static void main(String[] args) { //创建DRPC服务器 LocalDRPC drpc = new LocalDRPC(); //1、创建拓扑 TridentTopology topology = new TridentTopology(); topology.newDRPCStream("exclaimation", drpc).each(new Fields("args"), new ExclaimBolt(), new Fields("words")) .parallelismHint(5); //2、提交拓扑 LocalCluster cluster = new LocalCluster(); cluster.submitTopology("drpc-demo", new HashMap(), topology.build()); //3、客户端调用 String ss = "the cow jumped over the moon"; for(String s :ss.split(" ")){ //返回结果是一个KV格式,KEY为请求的id, V为最后一个bolt的返回结果。被封装成一个2个值的tuple。 System.out.println(drpc.execute("exclaimation", s)); } //4、关闭集群及drpc服务器 cluster.shutdown(); drpc.shutdown(); }} class ExclaimBolt extends BaseFunction{ @Override public void execute(TridentTuple tuple, TridentCollector collector) { String input = tuple.getString(0); collector.emit(new Values(input+"!")); }}
(三)RemoteDRPC:将DPRC拓扑提交至集群
1、启动DRPC服务器
先在storm集群的配置文件中加上:
drpc.servers: - "192.168.1.1"
然后在上述ip地址的机器上启动DRPC服务器,这台机器上需要有storm集群的配置文件
storm drpc
2、准备storm拓扑代码并提交
public class RemoteDRPCDemo { public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException { Config conf = new Config(); conf.setNumWorkers(5); //1、创建拓扑 TridentTopology topology = new TridentTopology(); topology.newDRPCStream("exclaimation").each(new Fields("args"), new ExclaimBolt2(), new Fields("words")) .parallelismHint(5); //2、提交拓扑 StormSubmitter.submitTopology("drpc-demo", conf, topology.build()); }}class ExclaimBolt2 extends BaseFunction{ @Override public void execute(TridentTuple tuple, TridentCollector collector) { String input = tuple.getString(0); collector.emit(new Values(input+"!")); }}
然后通过storm jar提交拓扑到集群中。
3、使用客户端发起请求
客户端需要指定DRPC的服务器地址与端口,然后发起请求,等待返回。
public class DRPCClientDemo { public static void main(String[] args) throws Exception { Config conf = new Config(); conf.setDebug(false); conf.put("storm.thrift.transport", "backtype.storm.security.auth.SimpleTransportPlugin"); conf.put(Config.STORM_NIMBUS_RETRY_TIMES, 3); conf.put(Config.STORM_NIMBUS_RETRY_INTERVAL, 10); conf.put(Config.STORM_NIMBUS_RETRY_INTERVAL_CEILING, 20); conf.put(Config.DRPC_MAX_BUFFER_SIZE, 1048576); DRPCClient client = new DRPCClient(conf, "192.168.1.1",3772); String ss = "the cow jumped over the moon"; for(String s :ss.split(" ")){ //返回结果是一个KV格式,KEY为请求的id, V为最后一个bolt的返回结果。被封装成一个2个值的tuple。 System.out.println(client.execute("exclaimation", s)); } }
0 0
- storm DRPC指南
- storm DRPC指南
- storm drpc
- Storm DRPC
- Storm DRPC
- Storm DRPC
- storm drpc
- Storm DRPC
- Twitter Storm: DRPC学习
- Twitter Storm: DRPC简介
- Storm DRPC 使用
- Twitter Storm: DRPC简介
- Twitter Storm: DRPC学习
- storm DRPC例子
- Twitter Storm: DRPC简介
- Storm DRPC实战
- Storm DRPC 介绍
- Twitter Storm: DRPC简介 .
- Bag of features
- cassandra在Windows上注册服务
- Git解决分支冲突及分支管理策略
- Ehcache学习总结(3)--Ehcache 整合Spring 使用页面、对象缓存
- Android Annotations配置与使用
- storm DRPC指南
- #pragma once 与#ifndef
- [3D 图形学基础] 读书笔记(2) Part_I(Getting Started) - Linear 线性
- Spring MVC、struts1和struts2区别
- mahout之推荐系统源码笔记(3) ---执行推荐之RecommenderJob
- VS2012环境编译驱动(根据网络教程改编)
- Java 二叉树(一)普通方式的创建
- DomReader工具
- Android,IOS QQ在线客服代码