storm1.1.0 drpc 部署和调用测试

一、配置集群storm.yaml文件,配置drpc.server

 

 

二、部署到linux上,开启nimbus,drpc,supervisor 等服务 

/opt/module/storm-1.1.0/bin/storm nimbus &

/opt/module/storm-1.1.0/bin/storm drpc &

/opt/module/storm-1.1.0/bin/storm supervisor &

/opt/module/storm-1.1.0/bin/storm ui &

 

三、编写DrpcTopology程序。如下:

/**
 * 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 com.eyecool.framework.olive.compute;

import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import org.apache.storm.LocalDRPC;
import org.apache.storm.StormSubmitter;
import org.apache.storm.drpc.LinearDRPCTopologyBuilder;
import org.apache.storm.utils.Utils;

import com.eyecool.framework.olive.compute.bolt.ExclamationBolt;

public class XFaceTopologyTest {

    public static void main(String[] args) throws Exception {
        run(args);
    }

    public static String spout_name = "raw-spout";

    protected static int run(String[] args) throws Exception {
        LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("lookup");
        builder.addBolt(new ExclamationBolt(),3);
        Config conf = new Config();
        conf.setDebug(false);
        conf.setNumWorkers(1);
        if (args != null && args.length > 0) {
            StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createRemoteTopology());
        } else {
            LocalDRPC drpc = new LocalDRPC();
            LocalCluster cluster = new LocalCluster();
            cluster.submitTopology("drpc-XFace", conf, builder.createLocalTopology(drpc));
            System.out.println("Results for 'hello':" + drpc.execute("lookup", "hello"));
            System.out.println("Results for 'hello':" + drpc.execute("lookup", "hello12"));

            Utils.sleep(1000000000);
            cluster.killTopology("drpc-XFace");
            cluster.shutdown();
        }
        return 0;
    }
}
View Code
package com.eyecool.framework.olive.compute.bolt;

import org.apache.storm.topology.BasicOutputCollector;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseBasicBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;

public class ExclamationBolt extends BaseBasicBolt {

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("id", "return-info"));
    }

    @Override
    public void execute(Tuple tuple, BasicOutputCollector collector) {
        Object arg = tuple.getValue(0);
        String retInfo = tuple.getString(1);
        System.out.println("v0: "+arg +" v1: "+retInfo);
        collector.emit(new Values(arg, retInfo + "!!!"));
    }

}
View Code

 

 

四、提交执行任务

/opt/module/storm-1.1.0/bin/storm jar olive-computeservice-storm-drpc-1.0.0-jar-with-dependencies.jar com.eyecool.framework.olive.compute.XFaceTopologyTest olive

 

五、页面可以看到系统成功运行

 

 

六、客户端代码调用测试,常遇到以下错误:

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
at org.apache.storm.security.auth.ThriftClient.reconnect(ThriftClient.java:108)
at org.apache.storm.security.auth.ThriftClient.<init>(ThriftClient.java:69)
at org.apache.storm.utils.DRPCClient.<init>(DRPCClient.java:44)
at org.apache.storm.utils.DRPCClient.<init>(DRPCClient.java:39)
at ClientTest.main(ClientTest.java:16)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at org.apache.storm.security.auth.AuthUtils.GetTransportPlugin(AuthUtils.java:267)
at org.apache.storm.security.auth.ThriftClient.reconnect(ThriftClient.java:89)
... 4 more
Caused by: java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.storm.security.auth.AuthUtils.GetTransportPlugin(AuthUtils.java:263)
... 5 more

 

import java.util.Map;

import org.apache.storm.Config;
import org.apache.storm.utils.DRPCClient;
import org.apache.storm.utils.Utils;

public class ClientTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Config conf = new Config();
            conf.setDebug(false);
            Map config = Utils.readDefaultConfig();
            @SuppressWarnings("resource")
            DRPCClient client = new DRPCClient(conf, "192.168.0.188", 3772);// drpc
            String result = client.execute("lookup", "hello world ");// 调用drpcTest函数,传递参数为hello
        
            System.out.println(result);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
View Code

 

正确的读取storm yaml 默认配置文件

Map config = Utils.readDefaultConfig();

 

 

 就这么简单,完成!!!

 

转载于:https://www.cnblogs.com/eyecool/p/7264974.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
部署 k8s 中的 ingress-controller v1.1.0,可以按照以下步骤进行操作: 1. 首先,确保 Kubernetes 集群已经可用并且已经正确设置。 2. 下载 ingress-controller v1.1.0 的安装文件。可以通过访问官方仓库或者 GitHub 并找到相关的发布版本进行下载。 3. 解压并配置 ingress-controller。通常可以通过编辑 YAML 文件来配置 ingress-controller,在其中指定一些关键参数,如使用的 ingress 类型、负载均衡器类型等。 4. 部署 ingress-controller。通过使用 kubectl 命令行工具,执行 `kubectl apply -f <配置文件>` 来完成 ingress-controller 的部署。 5. 确认 ingress-controller 已经成功部署。可以使用 `kubectl get pods -n <命名空间>` 命令来确认 ingress-controller 的运行状态。 6. 配置 ingress 规则。根据实际需求,编辑定义 ingress 规则的 YAML 文件并部署到 Kubernetes 中。 7. 确认 ingress 规则已经生效。可以通过 `kubectl get ingress -n <命名空间>` 命令来查看已部署的 ingress 规则,并确认其状态为 "RUNNING"。 8. 测试 ingress-controller。通过访问 ingress 规则中指定的域名或路径来确认 ingress-controller 是否成功地将请求转发到相应的服务。 这些步骤可以帮助您在 Kubernetes 中部署 ingress-controller v1.1.0,并通过 ingress 规则进行请求转发。在部署过程中,记得根据实际需求进行必要的配置和调整,以确保 ingress-controller 能够正常工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值