If your application uses a TCP-based SDK to access Message Queue for Apache RocketMQ, make sure that the application accesses the internal TCP endpoint of Message Queue for Apache RocketMQ in the same region as the application. This helps improve the stability of Message Queue for Apache RocketMQ and your application. This topic describes the region-specific internal TCP endpoints and how to configure them in code.

Release date

December 16, 2019

Announcement

You must switch to a region-specific internal TCP endpoint before June 30, 2020. A region-specific internal TCP endpoint provides higher stability than the original endpoint that you use to access Message Queue for Apache RocketMQ. After June 30, 2020, your original endpoint will become less stable.

The switch to a region-specific internal TCP endpoint brings the following effects:
  • If your application does not use Message Queue for Apache RocketMQ across regions, you do not need to modify the configurations of the publishers and subscribers at the same time.
  • If your application uses Message Queue for Apache RocketMQ across regions, you must determine the appropriate switching time based on your business. You can use Message Queue for Apache RocketMQ across regions by using an HTTP endpoint. For more information about HTTP-based SDKs, see Usage notes.
Note You can switch the access mode of an application that uses an open source SDK or Alibaba Cloud SDK to a region-specific internal TCP endpoint.

Determine whether switching is required

Check whether the internal TCP endpoint of your Message Queue for Apache RocketMQ instance contains a region ID. An endpoint that contains a region ID is in the format of http://xxxx.<region_id>.mq-internal.aliyuncs.com:<port>.
  • If your endpoint contains a region ID, you are not required to modify the endpoint configuration. For example, http://xxxx.cn-hangzhou.mq-internal.aliyuncs.com:8080 is an endpoint that contains a region ID.
  • If your endpoint does not contain a region ID, you must reconfigure the endpoint information used in your SDK by following the instructions provided in the Procedure section of this topic. For example, http://xxxx.mq-internal.aliyuncs.com:8080 is an endpoint that does not contain a region ID.

Background information

To send and receive messages in Message Queue for Apache RocketMQ by using a TCP-based SDK, set the following parameters based on the information about the resources that you want to use. Make sure that the resources involved in the following parameter settings are in the same region:

  • GROUP_ID: the ID of the group that you created in the Message Queue for Apache RocketMQ console.
  • Topic: the topic that you created in the Message Queue for Apache RocketMQ console.
  • NAMESRV_ADDR: the endpoint that you obtained from the Instance Details page in the Message Queue for Apache RocketMQ console.
For example, you have purchased Message Queue for Apache RocketMQ Instance A in the China (Hangzhou) region and created Topic A and Group A for Client A that is deployed in the region. You have also purchased Message Queue for Apache RocketMQ Instance B in another region, such as China (Shenzhen), and created Topic B and Group B for Client B that is deployed in the region. Take note of the following information:
  • To send messages to or receive messages from Topic A, you must use Client A that belongs to Group A in the China (Hangzhou) region.
  • To send messages to or receive messages from Topic B, you must use Client B that belongs to Group B in the China (Shenzhen) region.
The following figure shows specific mappings. Endpoint settings

Procedure

  1. Log on to the Message Queue for Apache RocketMQ console.
  2. In the left-side navigation pane, click Instances.
  3. In the top navigation bar, select a region such asChina (Hangzhou). Then, click the name of the instance for which you want to view the internal TCP endpoint.
  4. On the Instances page, click the Endpoints tab.
  5. In the TCP Endpoint section of the Endpoints tab, view the internal TCP endpoint in the row where the value in the Network column is Internal Access. Endpoints
  6. Modify the endpoint settings in the code of the publisher and subscriber.
    • If you use SDKs provided by Alibaba Cloud, make sure that the following conditions are met:

      The following sample code shows you how to modify the endpoint settings when the SDK for Java is used:

      // Make sure that your client version meets the requirements for switching the endpoint.
      properties.put(PropertyKeyConst.ONSAddr, "http://xxxx.mq-internal.aliyuncs.com:8080");          
      // Replace the preceding settings with the following settings:
      properties.put(PropertyKeyConst.NAMESRV_ADDR, "http://xxxx.cn-hangzhou.mq-internal.aliyuncs.com:8080");
    • The following sample code shows you how to modify the endpoint settings when the SDK for Java provided by open source RocketMQ is used:
      // Call the setNamesrvAddr method to specify the endpoint that you obtained from the Message Queue for Apache RocketMQ console. 
      producer.setNamesrvAddr("http://xxxx.cn-hangzhou.mq-internal.aliyuncs.com:8080");