TCP SDK

Last updated: 2020-02-17 18:14:37

PDF

CMQ currently provides SDK calls based on TCP Protocol, which supports the sending and receiving of ordinary messages, transaction messages, delayed messages and asynchronous messages. Among them, the transaction message feature is only implemented by TCP.
TCP Protocol currently supports the public network of Access and Intra-region 's VPC's CVM private network and Access, but does not support the basic network's private network and Access's.
This article mainly introduces the use of TCP SDK, and provides installation, download, configuration and running examples of Demo project to help engineers build CMQ test project quickly.

Advantages of TCP Protocol

  • Fewer computing resources
    For request authentication, HTTP requires a signature for each request; for link authentication, TCP only authenticates the link when the connection is established, saving client computing resources.
  • Safer client threads
    HTTP client is not thread-safe; TCP client is thread-safe, and multiple threads can use the same link, saving link resources.
  • More efficient transmission efficiency
    TCP transmission increases the proportion of effective data, and under the same client, it has higher throughput and more efficient transmission efficiency than HTTP compared with QPS,.
  • Better user experience
    TCP supports asynchronous interfaces and callbacks.
  • More diverse feature support
    TCP supports CMQ's latest distributed message transactions.

Demo project use

Prepare the Demo environment

  1. Install IDE
    You can install IntelliJ IDEA or Eclipse,. This article uses IntelliJ IDEA as an example.
    Please Download the IntelliJ IDEA Ultimate version And refer to the IntelliJ IDEA instructions for installation
  2. Download the Demo project
    Please Download the Demo project for CMQ When you unzip it locally, you can see the new local cmq-java-tcp-sdk-master folder.

Configure the Demo project

  1. Create Resource
    You need to create the required message queuing resources in the console, including CMQ queue name, SecretID, SecretKey.
    For the specific creation process, please refer to Queue model Getting Started and Topic model Getting Started .
  2. Import Demo project files
    Open the folder in the Start up interface of IDEA.

    After opening the folder, the file hierarchy is as follows, and the Demo project files are stored in the Demo folder.
  3. Configure Demo parameters
    Modify the file NameServer address, key pair and message queue name. For NameServer address, please refer to NameServer comparison table .
    Take ProducerDemo as an example, the configuration is as follows:
producer.setNameServerAddress(“Corresponding NameSever”);
producer.setSecretID(“Acquired SecretID”)
producer.setSecretKey(“Acquired SecretKey”)
String queue = “Name of the queue created”

The details are as follows:

Run Demo

Send and receive messages using queue model

  1. Configure Demo parameters .
  2. After the successful execution of the file ProducerDemo, the log is displayed as follows:

    ProducerDemo supports the sending of ordinary messages, delayed messages and asynchronous messages.
  3. The execution file ConsumerDemo, receives messages.

Send and receive messages using topic model

  1. Run the PublishDemo class to send messages in the topic model.
  2. Run the SubscriberDemo class to receive messages in topic mode.

Send and receive transaction messages

  1. Run the ProducerTransactionDemo class to send transaction messages.
  2. Run the SubscriberTransactionDemo class for transactional message reception.

">

Nameserver comparison table

Region Public network address VPC address
India Http://cmq-nameserver-in.tencentcloudapi.com Http://cmq-nameserver-vpc-in.api.tencentyun.com
Beijing Http://cmq-nameserver-bj.tencentcloudapi.com Http://cmq-nameserver-vpc-bj.api.tencentyun.com
Shanghai Http://cmq-nameserver-sh.tencentcloudapi.com Http://cmq-nameserver-vpc-sh.api.tencentyun.com
Guangzhou Http://cmq-nameserver-gz.tencentcloudapi.com Http://cmq-nameserver-vpc-gz.api.tencentyun.com
North America Http://cmq-nameserver-ca.tencentcloudapi.com Http://cmq-nameserver-vpc-ca.api.tencentyun.com
Chengdu Http://cmq-nameserver-cd.tencentcloudapi.com Http://cmq-nameserver-vpc-cd.api.tencentyun.com
Chongqing Http://cmq-nameserver-cq.tencentcloudapi.com Http://cmq-nameserver-vpc-cq.api.tencentyun.com
Hong Kong, China Http://cmq-nameserver-hk.tencentcloudapi.com Http://cmq-nameserver-vpc-hk.api.tencentyun.com
South Korea Http://cmq-nameserver-kr.tencentcloudapi.com Http://cmq-nameserver-vpc-kr.api.tencentyun.com
Russia Http://cmq-nameserver-ru.tencentcloudapi.com Http://cmq-nameserver-vpc-ru.api.tencentyun.com
Singapore Http://cmq-nameserver-sg.tencentcloudapi.com Http://cmq-nameserver-vpc-sg.api.tencentyun.com
Shanghai Finance Http://cmq-nameserver-shjr.tencentcloudapi.com Http://cmq-nameserver-vpc-shjr.api.tencentyun.com
Shenzhen Finance Http://cmq-nameserver-szjr.tencentcloudapi.com Http://cmq-nameserver-vpc-szjr.api.tencentyun.com
Thailand Http://cmq-nameserver-th.tencentcloudapi.com Http://cmq-nameserver-vpc-th.api.tencentyun.com
Meidong Http://cmq-nameserver-use.tencentcloudapi.com Http://cmq-nameserver-vpc-use.api.tencentyun.com
West America Http://cmq-nameserver-usw.tencentcloudapi.com Http://cmq-nameserver-vpc-usw.api.tencentyun.com