当前位置:网站首页>[in depth understanding of tcallusdb technology] example code - asynchronous call interface
[in depth understanding of tcallusdb technology] example code - asynchronous call interface
2022-04-22 15:14:00 【Database master】
This article suggests that
Java SDK Call of all interfaces , Both support asynchronous invocation mode .
In addition to data scanning related interfaces , There is a separate asynchronous invocation mode , The asynchronous calling mode of other interfaces is the same .
The difference from synchronous calls is , Synchronous calls use Client Of poll Method invocation , Asynchronous calls use Client Of post Method invocation .
preparation
See Chapter : preparation .
Sample code
This paper takes asynchronous data reading as an example , This paper introduces the asynchronous calling process of non data scanning interface .
Sample code
import com.tencent.tcaplus.client.Client;
import com.tencent.tcaplus.client.ClientFactory;
import com.tencent.tcaplus.client.Record;
import com.tencent.tcaplus.client.Request;
import com.tencent.tcaplus.client.Response;
import com.tencent.tdr.tcaplus_protocol_cs.TcaplusProtocolCsConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
public class Example {
public static void main(String[] arguments) throws InterruptedException {
// 1. Prepare environmental information
// 1.1. Directory service address list
List<String> dirList = new ArrayList<String>();
dirList.add("tcp://x.x.x.x:9999");
dirList.add("tcp://y.y.y.y:9999");
// 1.2. Business ID
int appId = 1;
// 1.3. Business password
String appPassword = "****************";
// 1.4. Table group ID
int tableGroupId = 1;
// 1.5. Table name
String tableName = "test";
// 2. Create client
Client client = ClientFactory.createClient(appId, tableGroupId, appPassword, dirList);
try {
// 3. Construct a request to query data
// 3.1. Get request object . In order to improve SDK performance ,Request Objects are reusable
Request request = client.acquireRequest();
// 3.2. Set request type and target table name
request.setCmd(TcaplusProtocolCsConstants.TCAPLUS_CMD_GET_REQ);
request.setTableName(tableName);
// 3.3. Set each Key Value of field
Record record = request.addRecord();
record.setKeyInt("gameid", 1);
record.setKeyInt("itemid", 1);
record.setKeyString("name", "test");
// 3.4. Add the to query Value Field
request.addFieldName("typeid");
request.addFieldName("Data");
request.addFieldName("uname");
CountDownLatch latch = new CountDownLatch(1);
// 4. Send requests asynchronously , And specify the processor that returns the result ,post Method will immediately return
client.post(request, new Future() {
@Override
public void onResponse(Response response) {
// 5. Processing results
if (response.getResult() == 0) {
// Query data successful
Record result = response.fetchRecord();
// TODO The subsequent processing code of successful data query can be added here
} else {
// Failed to query data
// TODO You can add the subsequent processing code of data query failure here
}
}
});
latch.await();
} finally {
// 6. Destroy client objects
ClientFactory.destroyClient(client);
}
}
}

TcaplusDB It's a distributed product of Tencent NoSQL database , The code for storage and scheduling is completely self-developed . With cache + Landing fusion architecture 、PB Levels of storage 、 Millisecond delay 、 Lossless horizontal expansion and complex data structure . At the same time, it has rich ecological environment 、 Easy migration 、 Extremely low operation and maintenance costs and five nine high availability features . Customer coverage game 、 Internet 、 government affairs 、 Finance 、 Manufacturing and the Internet of things .
版权声明
本文为[Database master]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221501395021.html
边栏推荐
- 云呐|最新酒店行业固定资产管理办法,酒店实物资产管理系统
- 记录一个sql,查询用户最后任职的一家公司,并根据企业名称+用户名称进行搜索
- redis 获取 list 中的所有元素
- 【深入理解TcaplusDB技术】扫描数据示例代码——[Generic表]
- 为什么别人做自媒体月入过万?你每天才几毛几块?有哪些变现方式?
- 【深入理解TcaplusDB技术】根据部分Key字段值读取数据示例代码——[Generic表]
- 2022 chemical automation control instrument examination question bank and online simulation examination
- 2022危险化学品经营单位主要负责人考试题模拟考试题库模拟考试平台操作
- Operation of simulated examination platform for examination questions of safety production management personnel of hazardous chemical production units in 2022
- 数据库操作
猜你喜欢

职场PUA,管理者的五宗罪

Tcallusdb Jun · industry news compilation (V)

What is the difference between the 1:1 attenuation ratio of multiple passive probes

TcaplusDB君 · 行业新闻汇编(五)

Vscode handles code merge conflicts

如何维护和应用高压隔离探头

琢磨琢磨方法引用以及lambda--白话Lambda和方法引用

Installation and use of distributed task scheduling platform xxl-job

顺序表——单向无头链表基础实现
![[Mysql] CHAR_LENGTH函数](/img/1c/57bc70f35429d0add2dbee99e06c1c.png)
[Mysql] CHAR_LENGTH函数
随机推荐
【深入理解TcaplusDB技术】更新数据示例代码——[Generic表]
How to import Cisco evng image simulator
【Yolact数据集制作-labelme使用与转coco详解】
【深入理解TcaplusDB技术】示例代码——异步调用接口
JVM的垃圾回收ParNew和CMS的介绍
如何通过云效Projex项目协同提高团队更高效的协作能力
【里程碑】WireGuard系列文章(七):使用WireGuard和Netmaker创建Full Mesh网络
ROS通信机制三---参数服务器
Transport layer UDP protocol
CommitFailedException异常,原因以及解决方案
SOLVE的妙用
Web automation testing framework realizes the operation of web elements through JS
数学史有没有必要读?关于数学教育,我们忽视了太多
多款无源探头1:1衰减比有什么区别
[Mysql] CHAR_LENGTH函数
Workplace PUA, five sins of managers
2022年化工自动化控制仪表考试题库及在线模拟考试
【深入理解TcaplusDB技术】异步扫描数据示例代码——[Generic表]
人脸识别 (4) 人脸对齐
「译文」如何在YAML中输入多行字符串?