赛尔校园公共服务平台 Logo
平台使用
阿里云
百度云
移动云
智算服务
教育生态
登录 →
赛尔校园公共服务平台 Logo
平台使用 阿里云 百度云 移动云 智算服务 教育生态
登录
  1. 首页
  2. 阿里云
  3. 表格存储
  4. 操作指南
  5. 消息模型
  6. 基础操作
  7. 初始化

初始化

  • 基础操作
  • 发布于 2025-04-22
  • 0 次阅读
文档编辑
文档编辑

使用消息模型时,您需要完成Factory、MetaStore和TimelineStore的初始化。本文介绍如何完成初始化的配置和操作。

前提条件

  • 已配置访问密钥。具体操作,请参考初始化Tablestore Client。

  • 已获取表格存储实例的Endpoint。具体操作,请参考初始化Tablestore Client。

初始化Factory

将SyncClient作为参数,初始化StoreFactory。通过Store工厂创建Meta数据和Timeline数据的管理Store。

实现错误重试需要依赖SyncClient的重试策略,您可以通过配置SyncClient实现重试。如果有特殊需求,可自定义策略(只需实现RetryStrategy接口)。

/**
 * 重试策略配置。
 * Code: configuration.setRetryStrategy(new DefaultRetryStrategy());
 **/
ClientConfiguration configuration = new ClientConfiguration();

SyncClient client = new SyncClient(
        "yourEndpoint",
        // 获取环境变量里的 AccessKey ID 和 AccessKey Secret
        System.getenv("TABLESTORE_ACCESS_KEY_ID"),
        System.getenv("TABLESTORE_ACCESS_KEY_SECRET"),
        "yourInstanceName", configuration);

TimelineStoreFactory serviceFactory = new TimelineStoreFactoryImpl(client);

初始化MetaStore

构建Meta表的Schema,包含Identifier、MetaIndex等参数,通过Store工厂创建并获取Meta的管理Store,配置参数包含Meta表名、索引名、主键字段、索引类型等。

TimelineIdentifierSchema idSchema = new TimelineIdentifierSchema.Builder()
        .addStringField("timeline_id").build();

IndexSchema metaIndex = new IndexSchema();
metaIndex.setFieldSchemas(Arrays.asList(//配置索引字段以及字段类型。
        new FieldSchema("group_name", FieldType.TEXT).setIndex(true).setAnalyzer(FieldSchema.Analyzer.MaxWord),
        new FieldSchema("create_time", FieldType.LONG).setIndex(true)
));

TimelineMetaSchema metaSchema = new TimelineMetaSchema("groupMeta", idSchema)
        .withIndex("metaIndex", metaIndex); //配置索引。

TimelineMetaStore timelineMetaStore = serviceFactory.createMetaStore(metaSchema);
  • 建表

    根据metaSchema的参数创建表。如果metaSchema中配置了索引,建表成功后会创建索引。

    timelineMetaStore.prepareTables();
  • 删表

    当表存在索引时,在删除表前,系统会先删除索引,再删除Store相应表。

    timelineMetaStore.dropAllTables();

初始化TimelineStore

构建timeline表的Schema配置,包含Identifier、TimelineIndex等参数,通过Store工厂创建并获取Timeline的管理Store;配置参数包含Timeline表名、索引名、主键字段、索引类型等。

消息的批量写入,基于Tablestore的DefaultTableStoreWriter提升并发,用户可以根据自己需求设置线程池数目。

TimelineIdentifierSchema idSchema = new TimelineIdentifierSchema.Builder()
        .addStringField("timeline_id").build();

IndexSchema timelineIndex = new IndexSchema();
timelineIndex.setFieldSchemas(Arrays.asList(//配置索引的字段以及字段类型。
        new FieldSchema("text", FieldType.TEXT).setIndex(true).setAnalyzer(FieldSchema.Analyzer.MaxWord),
        new FieldSchema("receivers", FieldType.KEYWORD).setIndex(true).setIsArray(true)
));

TimelineSchema timelineSchema = new TimelineSchema("timeline", idSchema)
        .autoGenerateSeqId() //SequenceId 设置为自增列方式。
        .setCallbackExecuteThreads(5) //设置Writer初始线程数为5。
        .withIndex("metaIndex", timelineIndex); //设置索引。

TimelineStore timelineStore = serviceFactory.createTimelineStore(timelineSchema);
  • 建表

    根据TimelineSchema的参数创建表。如果TimelineSchema中配置了索引,建表成功后会创建索引。

    timelineStore.prepareTables();
  • 删表

    当表存在索引时,在删除表前,系统会先删除索引,再删除Store相应的表。

    timelineStore.dropAllTables();
相关文章

初始化 2025-04-22 14:43

使用消息模型时,您需要完成Factory、MetaStore和TimelineStore的初始化。本文介绍如何完成初始化的配置和操作。 前提条件

Meta管理 2025-04-22 14:43

Meta管理提供了增、删、改、单行读、多条件组合查询等接口。 Meta管理的多条件组合查询功能基于多元索引,只有设置了IndexSchema的MetaStore才支持。索引类型支持LONG、DOUBLE、BOOLEAN、KEYWORD和GEO_POINT等类型,属性包含Index、Store和Arr

Timeline管理 2025-04-22 14:43

Timeline管理提供了消息模糊查询、多条件组合查询以及Flush接口。 Search Timeline管理的查询功能基于多元索引的Se

Queue管理 2025-04-22 14:43

本文介绍使用消息模型时如何进行Queue管理。 获取Queue实例 Queue是单个消息队列的抽象概念,对应TimelineStore下单

目录
Copyright © 2025 your company All Rights Reserved. Powered by 赛尔网络.
京ICP备14022346号-15
gongan beian 京公网安备11010802041014号