The currently supported regions include Internet, East China 1, East China 2, North China 2, and South China 1.
Scheduled messages can be consumed by consumers after a specified period, which are used in scenarios where there are time window requirements for message production and consumption, or when messages are used to trigger scheduled tasks, similar to delayed queues.
The following are sample codes for sending scheduled messages:
using namespace ons;
//Create producer and configure parameters required for sending messages;
factoryInfo.setFactoryProperty(ONSFactoryProperty::PublishTopics,"XXX" );//The topic you created on the MQ console
factoryInfo.setFactoryProperty(ONSFactoryProperty::MsgContent, "xxx");//msg content
factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, "xxx");//Alibaba Cloud ID verification, which is created on Alibaba Cloud Management Console
factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey, "xxx" );//Alibaba Cloud ID verification, which is created on Alibaba Cloud Management Console
Producer *pProducer = ONSFactory::getInstance()->createProducer(factoryInfo);
// Before sending messages, the start method must be called once to start the producer;
// Message topic
//Message tag, which is similar to tag in Gmail, and is used to classify messages. Consumers can then set filtering conditions for messages to be filtered in MQ broker.
//Message Body, which cannot be null. Serialization and deserialization methods need to be negotiated and remain consistent between the producer and the consumer.
// The setting represents the key service property of the message, so please set it as globally unique as possible.
// You can query a message and resend it through the MQ console when you cannot receive the message properly.
// Note: Normal sessage sending and receiving will not be affected if message key is not configured.
// Deliver time (ms) specifies the time point after which the message can be consumed. The example means that the message will be consumed after 3 seconds.
long deliverTime = obtain current system time (ms) + 3000;
// If no exceptions are thrown, then the message is sent successfully.
SendResultONS sendResult = pProducer->send(msg);
//Customize the details for processing exceptions
// The object Producer must be destroyed before exiting the application. Otherwise there will be memory leakage.
For instructions and example codes of subscribing to scheduled messages, see Subscribe Message.