You can use HTTP client SDKs for multiple programming languages to access ApsaraMQ for RocketMQ over the Internet. This topic describes the usage notes for HTTP client SDKs for multiple programming languages.
SDKs for multiple programming languages
ApsaraMQ for RocketMQ supports RESTful HTTP communication and provides SDKs for seven programming languages. More features are developed for HTTP client SDKs to align with the features that are supported by TCP client SDKs. For information about the differences between the features of HTTP client SDKs and TCP client SDKs, see the following topics:
Precautions
You can use the long polling mode or the short polling mode to obtain messages in ApsaraMQ for RocketMQ brokers for consumption over HTTP.
Long polling: The consumer sends a request to the broker to obtain messages in a specific topic. If no message exists in the topic, the broker suspends the request and returns a response until messages are produced in the topic or the specified period for the long polling elapses.
Short polling: If no message exists in the topic, the broker immediately returns a response. After the client receives the response, the client repeatedly initiates subscription requests.
The following items describe the configuration methods:
Long polling: When you initiate a subscription request, set the
waitSeconds
parameter to 0 or leave the parameter empty.Short polling: When you initiate a subscription request, set the
waitSeconds
parameter to a value that is greater than 0. The maximum value is 30 seconds.
For more information, see Operation for consuming messages.
If you use the short polling mode and no message is produced in the topic, a large number of invalid requests may be generated. You are charged API call fees for these requests. To reduce the number of invalid subscription requests and save costs, we recommend that you use the long polling mode and increase the waiting time for long polling. For information about how to calculate API call fees, see API call fees.
ImportantIf the number of consumers that are connected to an ApsaraMQ for RocketMQ instance over HTTP exceeds 100, the system automatically changes the long polling mode to the short polling mode. To ensure the stability of your business and the timeliness of message consumption, we recommend that you limit the number of connections on an instance.
You can use HTTP SDKs to access ApsaraMQ for RocketMQ instances. This is an enhanced feature provided by ApsaraMQ for RocketMQ. You cannot use HTTP SDKs to access self-managed Apache RocketMQ clusters.
Make sure that the resources that you want to access are in the same region as the HTTP endpoint that you use.
For example, if your ApsaraMQ for RocketMQ instance is deployed in the China (Hangzhou) region, you can use only an endpoint of the China (Hangzhou) region to access the instance. You can access the instance in the following scenarios:
If your client is located in the China (Hangzhou) region, we recommend that you use the private HTTP endpoint of the instance to access the instance.
If your client is not located in the China (Hangzhou) region, make sure that your client can connect to the Internet and use the public HTTP endpoint of the instance to access the instance.
Messages can be transmitted between TCP clients and HTTP clients. Message information such as attributes, content, tags, and keys must comply with Extensible Markup Language (XML) rules because HTTP uses XML serialization.
NoteFor more information about XML rules, see XML syntax. You can also use the third-party tool xml_validator to check whether your messages comply with XML rules based on your business requirements. For more information about xml_validator, see XML Validator.
If messages contain characters that do not comply with XML rules, the following errors may occur:
Messages fail to be sent over HTTP.
TCP messages fail to be consumed over HTTP.
You can use Base64 to encode or decode messages that are not complied with XML.