通讯指令手册

TxClient 与 TxManager 通讯指令说明文档

通讯指令数据包格式为Json格式

Json结构说明:

字段 数据类型 说明
key string 请求唯一标示
remoteKey string 请求资源方标示key
msg object 请求包数据体
msg.action string 请求业务方法名
msg.state int 请求状态 100:发起请求,200:响应成功,500:响应失败
msg.groupId string 事务组Id
msg.bytes byte[] 序列化请求数据

示例数据包:

请求包

{
	"key": "25303248287617950",
	"msg": {
		"action": "joinGroup",
		"state": 100,
		"bytes": "ChEyNTMwMzIyNDYxMjczODg4OBIgNGQ1NTcwMjc3Yzg1OTI5OTI5YWUxNDBiNjFlNjA3ZjAaA3R4Yw==",
		"groupId": "25303224612738888"
	},
	"remoteKey": "/127.0.0.1:8070"
}

响应包

{
	"key": "25303248287617950",
	"msg": {
		"action": "joinGroup",
		"state": 200,
		"groupId": "25303224612738888"
	},
	"remoteKey": "/127.0.0.1:59413"
}

  1. 创建事务组指令

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string createGroup 创建事务组key
state int 100 请求状态
groupId string 1234567890 事务组Id

响应参数:

字段 数据类型 说明
action string createGroup 创建事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
  1. 加入事务组指令

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string joinGroup 加入事务组
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
unitId string 1234567890 事务单元Id
unitType string lcn 事务类型(lcn/txc/tcc)
remoteKey string /127.0.0.1:8070 请求资源方标示key

响应参数:

字段 数据类型 说明
action string joinGroup 加入事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
  1. 通知事务组指令

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string notifyGroup 通知事务组
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
state int 0 或 1 代表发起方正常或者异常执行

响应参数:

字段 数据类型 说明
action string notifyGroup 通知事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
  1. 通知事务单元指令

请求方向:TxManager->TxClient

请求msg对象参数:

字段 数据类型 说明
action string notifyUnit 通知事务单元
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
unitId string 1234567890 事务单元Id
unitType string lcn 事务类型(lcn/txc/tcc)
state int 0 或 1 0 代表回滚,1代表提交

响应参数:

字段 数据类型 说明
action string notifyUnit 通知事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
  1. 事务单元检查事务状态

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string askTransactionState 通知事务组
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
unitId string 1234567890 事务单元Id

响应参数:

字段 数据类型 说明
action string askTransactionState 通知事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式(该序列化直接对Short对象做了序列化,无Object对象)

数据类型 说明
int 1、0、-1 0 代表回滚,1代表提交,-1将添加到异常状态
  1. 心跳指令

请求方向:TxManager->TxClient

格式如下:

{"key":"252356025399579923","msg":{"action":"h","state":1000}}
  1. 通知加入新的TxManager

请求方向:TxManager->TxClient

请求msg对象参数:

字段 数据类型 说明
action string newTxManager 通知事务组
state int 100 请求状态
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
host string 127.0.0.1 TxManager服务地址
port int 8082 TxManager服务端口

无需响应

  1. 客户端上报异常状态

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string writeException 通知事务组
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
unitId string 1234567890 事务单元Id
registrar short -1 0 1 2 异常情况 -1:未知, 0:TxManager通知事务,1:TxClient查询事务状态, 2:事务发起方通知事务组
transactionState short 1234567890 事务单元Id

无需响应

  1. 通知客户端获取事务切面日志

请求方向:TxManager->TxClient

请求msg对象参数:

字段 数据类型 说明
action string getAspectLog 通知事务组
state int 100 请求状态
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
unitId string 1234567890 事务单元Id

响应参数:

字段 数据类型 说明
action string getAspectLog 通知事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式(该序列化直接对Json对象做了序列化,无Object对象)

数据类型 说明
JsonObject {key:value} 切面日志json格式
  1. 客户端初始化指令

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string initClient 通知事务单元
state int 100 请求状态
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
appName string demo1 模块名称

响应参数:

字段 数据类型 说明
action string initClient 通知事务组
state int 200 响应成功
groupId string 1234567890 事务组Id
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
appName string demo1 模块名称
dtxTime int 30000 分布式事务执行最大时间(单位:毫秒)
tmRpcTimeout int 30000 TM RPC 超时时间(单位:毫秒)
seqLen int 12 雪花算法ID序列长度
分配的机器ID int 1 雪花算法分配的机器ID
  1. TXC询问分布式锁

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string qdtxl 询问分布式锁
state int 100 请求状态
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
groupId string 1234567890 事务组Id
contextId string 1234567890 应用模块位于标识
locks Set {“123”,”456”} 锁的数据内容
lockType int 1 共享锁:2,排他锁:1

响应参数:

字段 数据类型 说明
action string initClient 通知事务组
state int 200 响应成功
bytes byte[] 1234567890== 序列化请求数据包
序列化数据包内容格式为boolean类型,false true
  1. TXC释放分布式锁

请求方向:TxClient->TxManager

请求msg对象参数:

字段 数据类型 说明
action string rdtxl 释放分布式锁
state int 100 请求状态
bytes byte[] 1234567890== 序列化请求数据包

序列化数据包内容格式

字段 数据类型 说明
contextId string 1234567890 应用模块位于标识
locks Set {“123”,”456”} 锁的数据内容

响应参数:

字段 数据类型 说明
action string initClient 通知事务组
state int 200 响应成功
bytes byte[] 1234567890== 序列化请求数据包
序列化数据包内容格式为boolean类型,false true