首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Titan Framework 内部接口与函数说明书

HTTP与网络

Spring风格的Restful的Controller:

RestfulController通用Restful API Controller

–org.titan.framework.facade.controller.RestfulController

RestfulController进行HTTP API Path注释同Spring风格

Tips:RestfulController各方法中的ServiceName可以用于区分API版本号,并且进行API版本兼容处理,例如https:///login/v1 [POST]。

完整的RestfulController实例

QueryController通用查询专用APIController

–org.titan.framework.facade.controller.QueryController

完整的QueryController实例

org.titan.framework.facade.controller的自定义方式

Titan Framework对Controller的自定义方式类似Spring风格,如果曾经使用过SpringMVC的用户将会很快上手。

CommandHandler&Command通用指令模型

–org.titan.framework.facade.application.CommandHandler

–org.titan.framework.facade.application.Command

Titan Framework中采用如下逻辑进行Command捕捉与传递。

–第一步:Controller中return一个Command至Titan的Controller基类;

–第二步:Titan的Controller基类中将会完成Command类型的识别与自动匹配;

–第三步:Titan将Command发送到对应的应用层CommandHandler(注意:必须有@CmdHandler注释)

一个简单的CommandHandler案例如下:

Command&Command类型

Command是Titan框架中的指令单元,用来关联Controller与对应的具体处理逻辑,实现Controller与逻辑处理的解耦。Titan Framework为用户预置了下面这些Command类型,大家可以直接使用。

当然,大家也可以通过实现Command接口来自定义自己的Command。对于自定义Command,Titan Framework同样提供自动匹配支持。

Command中实现了以下默认方法:

Result与Result的使用

Result是Titan Framework中通用返回值的包装类,通过Result可以直接获取结果、状态、错误信息等。

Result有以下构造方式:

Titan内置的Result信号类型,可以快速构建对应的result:

Result的方法:

微服务远程调度

Publish&EventHandler

–org.titan.framework.facade.kit.Publish

–org.titan.framework.facade.event.EventHandler

Publish是Titan Framework的微服务远程调用入口,用于有针对性地向远程服务发起请求事件。

Publish有以下方法:

Publish的使用示例:

Send模式(Remote)

Send模式(Local)

与Publish相对应的是其他微服务的EventHandler,Publish发送Event,EventHandler接收响应Event。

EventHandler和CommandHandler类似,通过Event的类型来进行远程匹配。

EventHandler使用示例:

EventHandler中关键方法为Feedback.content(),用来通过非阻断的方式将处理结果返回至调用者。

Tips:自定义AppEvent和Result中都可以携带数据进行返回,Titan官方不建议返回数据过大,如果需要返回大量数据或者二进制流数据,可以通过Event驱动加MessageQueue的方式进行处理。

数据库&消息队列支持

Titan Framework对MySql、MongoDB、Redis提供直接支持。

TitanFramework的MySql支持

Titan与Mysql的对接包括以下三部分:

–conf包下的mysql.properties

–spring包下的application-dynamic-ds-context.xml、application-context.xml

–基于Titan SpringMysqlRepository、SpringMysqlFindRepository的功能模块

其中SpringMysqlRepository是数据库写模型,SpringMysqlFindRepository是数据库读模型。

SpringMySqlRepository用法如下:

SpringMysqlRepository中包含以下方法:

SpringMysqlFindRepository示例如下:

mysql.properties示例如下:

application-context.xml示例如下:

application-dynamic-ds-context.xml示例如下:

TitanFramework的MongoDB支持

Titan与MongoDB的对接包括以下两部分:

–spring包下的application-mongoDB-context.xml、application-context.xml

–conf包下的mongoDB.properties

基于Titan MongodbRepository的功能模块

其中需要实现StorageDataProcessor.Mongo。

MongodbRepository用法如下:

application-mongoDB-context.xml示例如下:

application-context.xml示例如下:

mongoDB.properties示例如下:

TitanFramework的Redis支持

Titan与Mysql的对接包括以下三部分:

–spring包下的application-redis-context.xml、application-context.xml

–conf包下的redis.properties

–基于Titan ShardedJedisPool的功能模块

ShardedJedisPool用法如下:

application-redis-context.xml用法如下:

application-context.xml用法如下:

redis.properties用法如下:

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180620A1EQ4100?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券