Refer to the example below to send messages.
using namespace ons;
//Create producer and configure parameters required for sending messages;
factoryInfo.setFactoryProperty(ONSFactoryProperty::PublishTopics,"XXX" );// Message content
factoryInfo.setFactoryProperty(ONSFactoryProperty::MsgContent, "XXX");//Message content
factoryInfo.setFactoryProperty(ONSFactoryProperty::AccessKey, "XXX");//AccessKey, Alibaba Cloud ID verification, which is created on Alibaba Cloud Management Console
factoryInfo.setFactoryProperty(ONSFactoryProperty::SecretKey, "XXX" );//SecretKey, 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 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 business property of the message, so please keep it globally unique.
// 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.
// If no exceptions are thrown, then the message is sent successfully.
SendResultONS sendResult = pProducer->send(msg);
catch(ONSClientException & e)
//Customize the details for processing the exception
// The object Producer must be destroyed before exiting the application. Otherwise there will be memory leakage.
For instructions and sample codes of subscribing to standard messages, see Subscribe to messages.