Last updated: 2020-04-16 10:56:49

    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:// Http://
    Beijing Http:// Http://
    Shanghai Http:// Http://
    Guangzhou Http:// Http://
    North America Http:// Http://
    Chengdu Http:// Http://
    Chongqing Http:// Http://
    Hong Kong, China Http:// Http://
    South Korea Http:// Http://
    Russia Http:// Http://
    Singapore Http:// Http://
    Shanghai Finance Http:// Http://
    Shenzhen Finance Http:// Http://
    Thailand Http:// Http://
    Meidong Http:// Http://
    West America Http:// Http://

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback