你的位置:首页 > 软件开发 > 数据库 > dotNET使用DRPC远程调用运行在Storm上的Topology

dotNET使用DRPC远程调用运行在Storm上的Topology

发布时间:2015-08-14 21:00:11
Distributed RPC(DRPC)是Storm构建在Thrift协议上的RPC的实现,DRPC使得你可以通过多种语言远程的使用Storm集群的计算能力。DRPC并非Storm的基础特性,但它确实非常有用。DRPC的整个过程与一般的RPC没有区别,客户端只需要调用一个远程的 ...

 Distributed RPC(DRPC)是Storm构建在Thrift协议上的RPC的实现,DRPC使得你可以通过多种语言远程的使用Storm集群的计算能力。DRPC并非Storm的基础特性,但它确实非常有用。DRPC的整个过程与一般的RPC没有区别,客户端只需要调用一个远程的方法并等待返回结果。主要工作已经被DRPC Server封装,服务端在这个过程中完成了以下步骤:

  • 从客户端接收一个RPC请求;
  • 将请求发送到storm topology;
  • 从storm topology接收结果;
  • 将结果发回给等待的客户端。

dotNET使用DRPC远程调用运行在Storm上的Topology

storm-net-adapter现在已经完成了对DRPC的支持,因此你可以使用dotNet编写代码远程调用任何支持语言编写的支持DRPC的Topology,当然你也可以使用dotNet编写Topology供其它语言通过DRPC调用。

DRPC是storm-net-adapter新增加的特性,因此需要使用最新的类库,你可以使用源代码自行编译,或者下载最新的Release,还可以使用Nuget获取最新版本。

PM> Install-Package Storm.Net.Adapter

推荐大家使用Nuget获取,方便管理依赖项。下面将介绍如何通过DRPC调用运行在Storm集群的方法,在这之前,你需要已经熟悉Storm环境的搭建与集群部署,不了解的可以先看我之前的文章。为了尽可能的简单,我们使用了Storm官方的BasicDRPCTopology,这个是一个简单的使用JAVA编写的DRPC Topology,它的功能仅仅是在传入的单词后面增加一个感叹号。

/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package storm.starter;import backtype.storm.Config;import backtype.storm.LocalCluster;import backtype.storm.LocalDRPC;import backtype.storm.StormSubmitter;import backtype.storm.drpc.LinearDRPCTopologyBuilder;import backtype.storm.topology.BasicOutputCollector;import backtype.storm.topology.OutputFieldsDeclarer;import backtype.storm.topology.base.BaseBasicBolt;import backtype.storm.tuple.Fields;import backtype.storm.tuple.Tuple;import backtype.storm.tuple.Values;/** * This topology is a basic example of doing distributed RPC on top of Storm. It implements a function that appends a * "!" to any string you send the DRPC function. * <p/> * See https://github.com/nathanmarz/storm/wiki/Distributed-RPC for more information on doing distributed RPC on top of * Storm. */public class BasicDRPCTopology { public static class ExclaimBolt extends BaseBasicBolt {  @Override  public void execute(Tuple tuple, BasicOutputCollector collector) {   String input = tuple.getString(1);   collector.emit(new Values(tuple.getValue(0), input + "!"));  }  @Override  public void declareOutputFields(OutputFieldsDeclarer declarer) {   declarer.declare(new Fields("id", "result"));  } } public static void main(String[] args) throws Exception {  LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("exclamation");  builder.addBolt(new ExclaimBolt(), 3);  Config conf = new Config();  if (args == null || args.length == 0) {   LocalDRPC drpc = new LocalDRPC();   LocalCluster cluster = new LocalCluster();   cluster.submitTopology("drpc-demo", conf, builder.createLocalTopology(drpc));   for (String word : new String[]{ "hello", "goodbye" }) {    System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word));   }   cluster.shutdown();   drpc.shutdown();  }  else {   conf.setNumWorkers(2);   StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createRemoteTopology());  } }}

原标题:dotNET使用DRPC远程调用运行在Storm上的Topology

关键词:dotnet

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录