-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
using Storm.DRPC; | ||
using System; | ||
|
||
namespace Storm.DRPC.Demo | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
DRPCClient client = new DRPCClient("drpc-host", 3772); | ||
DRPCClient client = new DRPCClient("localhost", 3772); | ||
string result = client.execute("exclamation", "hello word"); | ||
Console.WriteLine(result); | ||
Console.WriteLine("Please input a word and press enter, if you want quit it, press enter only!"); | ||
do { | ||
string input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) | ||
break; | ||
|
||
Console.WriteLine(client.execute("exclamation", input)); | ||
} | ||
while (true); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
storm-starter/src/jvm/storm/starter/BasicDRPCTopology.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* 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(3); | ||
StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createRemoteTopology()); | ||
} | ||
} | ||
} |
Binary file not shown.