Skip to content

Publish in the Future

The example demonstrates scheduling a message to be delivered on January 1st, 2030 at 00:00 Central time. The message is published into the demo channel:

DeliveryOptions deliveryOptions = new DeliveryOptions();

DateTime publishDate = new DateTime( TimeSpan.FromMilliseconds( 1893477600000 ).Ticks );
deliveryOptions.PublishAt = publishDate;

AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
   messageStatus =>
   {
     Console.WriteLine( $"message has been published {messageStatus.MessageId}"); 
   },
   fault =>
   {
     Console.WriteLine( $"error {fault.Message}");
   } 
);

Backendless.Messaging.Publish( "demo",
                               "Happy New Year!",
                               null, // this is null since a PublishOptions object is not provided
                               // see the "Conditional Pub/Sub" section for an example of how
                               // to use the PublishOptions object for this argument
                               deliveryOptions,
                               callback );

Codeless Reference

To subscribe to a channel refer to the Subscribe for All Messages topic.

pubsub_api_basic_publish_1

where:

Argument                Description
channel name Name of the channel where a message must be published to.
subtopic name The subtopic of the message allows developers to designate and filter messages by subtopic name. For instance, if a messaging application has a group and a few subgroups, all messages sent to the main group can be marked with this subtopic name which can be used to route messages to the appropriate subgroups depending on the context.
message The contents of the message that must be published to a channel.
headers Message headers is a collection of name/value pairs. A subscriber can set a filter expressed as an SQL "where clause" query (called selector) which Backendless uses to determine whether a message should be delivered to the subscriber. When the query matches the published data in message headers, message is delivered to the corresponding subscriber. For more information see the Conditional Delivery section of this guide.
publish at Must be a Unix Timestamp, which is the number of milliseconds since the Epoch (January 1st, 1970 at UTC).  Note that if you want to specify the number of seconds instead of milliseconds, you must multiply the number by 1000 or add three trailing zeroes to your number (e.g. (1681324179 * 1000) or 1681324179000.
return result When this box is checked, the operation returns an object containing the status of the message delivery and a unique message identifier.

Returns an object containing the status of the message delivery and a unique message identifier:

// Sample object  

{  
    "errorMessage":null,  
    "messageId":"message:FCBD8BF1-A45D-4564-B449-3C91D4896987",  
    "status":"published"  
}

The example below publishes the message to the "demo" channel. The publish at property has been set to publish the message at 1893477600000 Unix time.

pubsub_api_publishing_in_the_future