TCP client SDKs can be used to connect to ApsaraMQ for RocketMQ instances. To ensure the stability of your business application, configure the private TCP endpoint for the region where your ApsaraMQ for RocketMQ instance is deployed in your TCP client SDK. This topic describes the region-specific private TCP endpoints and how to configure them in code.
Initial release date
December 16, 2019
Announcement
You must change the endpoint that is configured in the SDK to a region-specific private TCP endpoint before June 30, 2023. A region-specific private TCP endpoint provides higher stability than the original endpoint that you use to access Message Queue for Apache RocketMQ. After June 30, 2023, the original endpoint can not be used to send or subscribe to messages.
Before you configure a region-specific private TCP endpoint in the SDK, take note of the following items:
If your application does not use ApsaraMQ for RocketMQ instances across regions, you do not need to modify the configurations of producers and consumers.
If your application uses ApsaraMQ for RocketMQ instances across regions, you must determine the appropriate switching time based on your business requirements. You can use an HTTP endpoint to access ApsaraMQ for RocketMQ instances across regions. For information about HTTP client SDKs, see Usage notes.
You can configure region-specific private TCP endpoints in open source SDKs or Alibaba Cloud SDKs.
Determine whether switching is required
Check whether the private TCP endpoint of your ApsaraMQ for RocketMQ instance includes a region ID. The endpoint must be in the http://xxxx.<region_id>.mq-internal.aliyuncs.com:<port>
format.
If the endpoint includes a region ID, you do not need to modify the endpoint configuration. For example, http://xxxx.cn-hangzhou.mq-internal.aliyuncs.com:8080 is an endpoint that includes a region ID.
If the endpoint does not include a region ID, you must reconfigure the endpoint information that is 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 include a region ID.
Background information
If you want to use a TCP client SDK to send and subscribe to messages in ApsaraMQ for RocketMQ, configure resource parameters based on the information about the resources that you want to use. Make sure that the resources that are specified for the GROUP_ID, Topic, and NAMESRV_ADDR parameters are deployed in the same region.
GROUP_ID: the ID of the group that you created in the ApsaraMQ for RocketMQ console.
Topic: the topic that you created in the ApsaraMQ for RocketMQ console.
NAMESRV_ADDR: the endpoint that you obtained from the Instance Details page in the ApsaraMQ for RocketMQ console.
For example, ApsaraMQ for RocketMQ Instance A is deployed in the China (Hangzhou) region, and Topic A and Group A are created in Instance A for Client A that is deployed in the China (Hangzhou) region. ApsaraMQ for RocketMQ Instance B is deployed in another region, such as China (Shenzhen), and Topic B and Group B are created in Instance B for Client B that is deployed in the China (Shenzhen) region. Take note of the following items:
To send messages to or subscribe to messages from Topic A, use Client A that belongs to Group A in the China (Hangzhou) region.
To send messages to or subscribe to messages from Topic B, use Client B that belongs to Group B in the China (Shenzhen) region.
The following figure shows the endpoints that correspond to regions.
Procedure
Log on to the ApsaraMQ for RocketMQ console.
In the left-side navigation pane, click Instances.
In the top navigation bar, select a region such as China (Hangzhou). Then, click the name of the instance for which you want to view the private TCP endpoint.
On the Instances page, click the Endpoints tab.
In the TCP Endpoint section of the Endpoints tab, view the private TCP endpoint in the row where the value in the Network column is Internal Access.
Modify the endpoint settings in the code of the producer and the consumer.
The following versions of Alibaba Cloud SDKs support region-specific private TCP endpoints:
The SDK for Java: Release notes or later
The SDK for C or C++: Release notes or later
The SDK for .NET: Release notes or later
The following sample code provides an example on how to modify the endpoint settings when the SDK for Java is used:
// Make sure that your client version supports changing 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 provides an example on how to modify the endpoint settings when the SDK for Java provided by open source Apache 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");