HBase 实战微博系统
必学容器技术基础
一、需求分析
- 微博内容的浏览,数据库表设计
- 用户社交体现:关注用户,取关用户
- 拉取关注的人的微博内容
二、代码实现
2.1 代码设计总览
- 创建命名空间以及表名的定义
- 创建微博内容表
- 创建用户关系表
- 创建用户微博内容接收邮件表
- 发布微博内容 6)
添加关注用户- 移除(取关)用户
- 获取关注的人的微博内容
- 测试
2.2 创建命名空间以及表名的定义
package org.example.contants;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
public class Constants {
//HBASE配置信息
public static Configuration CONFIGURATION = HBaseConfiguration.create();
//HBASE命名空间
public static String NAMESPACE = "weibo";
//微博内容表
public static String CONTENT_TABLE = "weibo:content";
public static String CONTENT_TABLE_CF = "info";
public static int CONTENT_TABLE_VERSIONS = 1;
//用户关系表
public static String RELATION_TABLE = "weibo:relation";
public static String RELATION_TABLE_CF1 = "attends";
public static String RELATION_TABLE_CF2 = "fans";
public static int RELATION_TABLE_VERSIONS = 1;
//收件箱表
public static String INBOX_TABLE = "weibo:index";
public static String INBOX_TABLE_CF = "info";
public static int INBOX_TABLE_VERSIONS = 2;
}
2.3 创建微博内容表
方法名 | creatTableeContent |
---|---|
Table Name weibo:content | weibo:content |
RowKey | 用户 ID_时间戳 |
ColumnFamily | info |
ColumnLabe | 标题,内容,图片 |
Version | 1 个版本 |