•RPC,远程方法调用。通过发布一个服务
•1:Trident上的drpc,2:spout和bolt上drpc。
•eclipse本地调试模式
TridentTopology.newDRPCStream(function,ILocalDRPC)
ILocalDRPC.execute(function,args);
•部署到storm环境后
TridentTopology.newDRPCStream(function)
DRPCClient.execute(function,args);
需求:
SELECT tel,SUM(money) FROM u GROUP BY tel WHERE tel = ?
-----------------配套视频----------------------------------------
http://pan.baidu.com/s/1kT5kecn
-----------------配套代码----------------------------------------
package storm.test.trident;
import liguozhong.trident.state.mysql.MysqlState;
import liguozhong.trident.state.mysql.MysqlStateConfig;
import org.apache.thrift7.TException;
import storm.trident.Stream;
import storm.trident.TridentState;
import storm.trident.TridentTopology;
import storm.trident.operation.builtin.MapGet;
import storm.trident.spout.IBatchSpout;
import storm.trident.state.StateType;
import storm.trident.testing.FixedBatchSpout;
import backtype.storm.Config;
import backtype.storm.ILocalDRPC;
import backtype.storm.LocalCluster;
import backtype.storm.LocalDRPC;
import backtype.storm.generated.DRPCExecutionException;
import backtype.storm.generated.StormTopology;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;
public class _06DRPC {
public static void main(String[] args) throws Exception {
String tel = "135111";
ILocalDRPC localDRPC = getServer();
String result = localDRPC.execute(
"SELECT tel,SUM(money) FROM u GROUP BY tel WHERE tel = ?", tel);
System.err.println("DRPC请求结果:"+result);
}
private static IBatchSpout getBatch() {
// SELECT tel,SUM(money) FROM u GROUP BY tel
FixedBatchSpout batchSpout = new FixedBatchSpout(new Fields("tels"), 3,
new Values("189111 4"), new Values("135111 9"), new Values(
"189111 8"), new Values("158111 3"), new Values(
"158111 3"));
return batchSpout;
}
private static ILocalDRPC getServer() {
ILocalDRPC localDRPC = new LocalDRPC();
IBatchSpout batchSpout = getBatch();
TridentTopology tt = new TridentTopology();
Stream stream = tt.newStream("_01Stream", batchSpout);
// SELECT tel,SUM(money) FROM u GROUP BY tel
final String dburl = "jdbc:mysql://localhost:3306/tel?user=root&password=root";
//
MysqlStateConfig mysqlStateConfig = new MysqlStateConfig();
mysqlStateConfig.setBatchSize(1000);
mysqlStateConfig.setCacheSize(5000);
mysqlStateConfig.setKeyColumns(new String[] { "tel" });
mysqlStateConfig.setTable("tel");
mysqlStateConfig.setType(StateType.NON_TRANSACTIONAL);
mysqlStateConfig.setUrl(dburl);
mysqlStateConfig.setValueColumns(new String[] { "money" });
TridentState tridentState = stream.each(new Fields("tels"),
new KeyValueFunction(), new Fields("tel", "money")).groupBy(
new Fields("tel"))//
.persistentAggregate(MysqlState.newFactory(mysqlStateConfig),
new Fields("money"), new SumCombinerAgg(),
new Fields("sum"));
tt.newDRPCStream("SELECT tel,SUM(money) FROM u GROUP BY tel WHERE tel = ?",localDRPC)//
.groupBy(new Fields("args"))//
.stateQuery(tridentState,new Fields("args"), new MapGet(), new Fields("sum"));//
// 转化成第一个编程模型
StormTopology stormTopology = tt.build();
Config config = new Config();
LocalCluster localCluster = new LocalCluster();
localCluster.submitTopology("_02Filter", config, stormTopology);
return localDRPC;
}
}
-----------------配套视频----------------------------------------
http://pan.baidu.com/s/1kT5kecn#path=%252Fstorm%25E5%2588%2586%25E4%25BA%25AB%25E8%25A7%2586%25E9%25A2%2591
-----------------配套视频----------------------------------------
http://pan.baidu.com/s/1kT5kecn#path=%252Fstorm%25E5%2588%2586%25E4%25BA%25AB%25E8%25A7%2586%25E9%25A2%2591