main() メソッドに 2 つの別個のトポロジがあります。「for ループ」を使用して、対応するスパウトとボルトを設定し、そのトポロジも送信しています。各トポロジには、異なるロジックを持つスパウトとボルトの個別のセットがあります。
ここで、さまざまなスパウトとボルトを動的に呼び出したいと思います。どうやってやるの ??
メインメソッドのコード:
public static void main(String[] args) throws InterruptedException,Exception
{
LocalCluster cluster = new LocalCluster();
try{
BufferedReader in=new BufferedReader(new FileReader("/home/praveen /workspace/OfferEngine/OfferListJSON.json"));
//ArrayList<String> content = new ArrayList<String>();
String str="";
String str1="";
while((str1=in.readLine())!=null)
{
str = str + str1;
}
JsonParser parser = new JsonParser();
JsonObject o = (JsonObject)parser.parse(str);
JsonObject o2 = (JsonObject)o.get("OfferData");
ArrayList<String> ol = new ArrayList<String>();
ol.add(o2.get("strOfferId").toString().replaceAll("^\"|\"$", ""));
ol.add(o2.get("strOfferId1").toString().replaceAll("^\"|\"$", ""));
TopologyBuilder bu = null;
Config config = new Config();
config.setDebug(false);
for(String x : ol) {
System.out.println(x); //prints element x
String y="", z="";
bu = new TopologyBuilder();
bu.setSpout(x, new Off1Spout(x).ks(), 2);
y = x+"2";
bu.setBolt(y, new main.java.bolts.Off1Bolt()).shuffleGrouping(x);
z = x+"offerlimit";
bu.setBolt(z, new OfferLimit()).shuffleGrouping(y);
cluster.submitTopology(x,config,bu.createTopology());
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
どんな種類の提案もより役に立ちます...よろしくお願いします