lume+kafka+storm+mysql 数据流

41 篇文章 0 订阅
27 篇文章 0 订阅

今天终于将 flume + kafka + storm + mysql 这条数据流走通了,虽然只是一个简单的测试例子,但是依据这条数据流可以做的事情很多。

先简单看一下这几个工具的架构吧,架构图会更好说明:


flume的架构图:


kafka的架构图:



storm的架构图:


我们使用的  flume + kafka + storm +mysql的数据流架构图:

下面介绍一下kafka到storm的配置:

其实这些都是通过java代码实现的,这里用到了 KafkaSpout类,RDBMSDumperBolt类(以后这些可以作为工具类打包上传到集群中)

storm作业中,我们写了一个KafkaStormRdbms类,作业具体配置如下:

首先设置连接mysql的参数:

  1. ArrayList<String> columnNames = new ArrayList<String>();  
  2. ArrayList<String> columnTypes = new ArrayList<String>();  
  3. String tableName = "stormTestTable_01";  
  4. // Note: if the rdbms table need not to have a primary key, set the variable 'primaryKey' to 'N/A'  
  5. // else set its value to the name of the tuple field which is to be treated as primary key  
  6. String primaryKey = "N/A";  
  7. String rdbmsUrl = "jdbc:mysql://$hostname:3306/fuqingwuDB" ;  
  8. String rdbmsUserName = "fuqingwu";  
  9. String rdbmsPassword = "password";  
  10.   
  11. //add the column names and the respective types in the two arraylists  
  12. columnNames.add("word");  
  13.   
  14. //add the types  
  15. columnTypes.add("varchar (100)");  

配置 KafkaSpout 及 Topology:
  1. TopologyBuilder builder = new TopologyBuilder();  
  2.           
  3.         List<String> hosts = new ArrayList<String>();  
  4.         hosts.add("hadoop01");  
  5.         SpoutConfig spoutConf = SpoutConfig.fromHostStrings(hosts, 1"flume_kafka""/root""id");  
  6.         spoutConf.scheme = new StringScheme();  
  7.         spoutConf.forceStartOffsetTime(-2);  
  8.           
  9.         spoutConf.zkServers = new ArrayList<String>() {{  
  10.                       add("hadoop01");   
  11.                     }};  
  12.         spoutConf.zkPort = 2181;  
  13.           
  14.         //set the spout for the topology  
  15.         builder.setSpout("spout",  new KafkaSpout(spoutConf), 1);  
  16.   
  17.         //dump the stream data into rdbms table       
  18.         RDBMSDumperBolt dumperBolt = new RDBMSDumperBolt(primaryKey, tableName, columnNames, columnTypes, rdbmsUrl, rdbmsUserName, rdbmsPassword);  
  19.         builder.setBolt("dumperBolt",dumperBolt, 1).shuffleGrouping("spout"); 


原文地址: http://blog.csdn.net/baiyangfu_love/article/details/8096088

lume()分别用于求圆的面积和体积,然后在Circle类的基础上分别派生出Sphere类和Cylinder类。在Sphere类中重新定义area()和volume()函数以求球体的面积和体积,在Cylinder类中重新定义area()和volume()函数以求圆柱体的面积和体积。最后在主函数中创建对象并调用相应的函数计算并输出结果。 具体实现如下: ```c++ #include <iostream> using namespace std; class Circle { protected: double radius; // 圆的半径 public: Circle(double r=0) { radius = r; } virtual double area() { return 0; } // 求圆的面积(虚函数) virtual double volume() { return 0; } // 求圆的体积(虚函数) }; class Sphere: public Circle { public: Sphere(double r=0): Circle(r) {} virtual double area() { return 4 * 3.14 * radius * radius; } // 求球体的表面积(重定义虚函数) virtual double volume() { return 4/3.0 * 3.14 * radius * radius * radius; } // 求球体的体积(重定义虚函数) }; class Cylinder: public Circle { protected: double height; // 圆柱体的高 public: Cylinder(double r=0, double h=0): Circle(r), height(h) {} virtual double area() { return 2 * 3.14 * radius * (radius + height); } // 求圆柱体的表面积(重定义虚函数) virtual double volume() { return 3.14 * radius * radius * height; } // 求圆柱体的体积(重定义虚函数) }; int main() { Circle *p; // 定义指向圆类对象的指针 Sphere s(5); // 创建球体对象 Cylinder c(3, 8); // 创建圆柱体对象 p = &s; // 指针指向球体对象 cout << "球体的表面积:" << p->area() << endl; // 调用球体的area()函数 cout << "球体的体积:" << p->volume() << endl; // 调用球体的volume()函数 p = &c; // 指针指向圆柱体对象 cout << "圆柱体的表面积:" << p->area() << endl; // 调用圆柱体的area()函数 cout << "圆柱体的体积:" << p->volume() << endl; // 调用圆柱体的volume()函数 return 0; } ``` 输出结果为: ``` 球体的表面积:314 球体的体积:523.333 圆柱体的表面积:150.72 圆柱体的体积:226.08 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值