The currently supported domains 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:
static void Main(string args)
//A mandatory parameter required for the producer creation and message handling
ONSFactoryProperty factoryInfo = new ONSFactoryProperty();
factoryInfo.setFactoryProperty(factoryInfo.ProducerId, "XXX ");//The producer ID you created on the MQ console
factoryInfo.setFactoryProperty(factoryInfo.PublishTopics, "XXX");//The topic you created on the MQ console
factoryInfo.setFactoryProperty(factoryInfo.MsgContent, "XXX");//Message content
factoryInfo.setFactoryProperty(factoryInfo.AccessKey, "XXX");//AccessKey, Alibaba Cloud ID verification, which is created on Alibaba Cloud Management Console
factoryInfo.setFactoryProperty(factoryInfo.SecretKey,"XXX");//SecretKey, Alibaba Cloud ID verification, which is created on Alibaba Cloud Management Console
//Create a producer
ONSFactory onsfactory = new ONSFactory();
Producer pProducer = onsfactory.getInstance().createProducer(factoryInfo);
//Before sending messages, the start method must be called once to start the producer.
Message msg = new Message(
// 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);
//Handle the message sending failures
//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 to messages.