Skip to content

Delayed Delivery

Publishers can specify the time when the message should be processed and delivered to subscribers. This can be done in addition to all other publishing options (basic publish, with headers. Scheduled messages can be canceled at any time using the message cancellation API.

Blocking Publish

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PublishAt = DateTime.Now.AddSeconds( 20 );

MessageStatus status = Backendless.Messaging.Publish( "This message was scheduled 20 seconds ago", deliveryOptions );
System.Console.WriteLine( $"Message scheduled. Message ID - {status.MessageId}. Message Status - {status.Status}" );

if( status.Status == PublishStatusEnum.FAILED )
  System.Console.WriteLine( $"Message publish failed with error {status.ErrorMessage}" );

Non-blocking Publish

AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
        result =>
        {
          System.Console.WriteLine( $"Message scheduled. Message ID - {result.MessageId}. Message Status - {result.Status}" );

          if( result.Status == PublishStatusEnum.FAILED )
            System.Console.WriteLine( $"Message publish failed with error {result.ErrorMessage}" );
        },
        fault =>
        {
          System.Console.WriteLine( "Error - " + fault );
        } );

DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PublishAt = DateTime.Now.AddSeconds( 20 );

Backendless.Messaging.Publish( "This message was scheduled 20 seconds ago", deliveryOptions, callback );

Codeless Reference

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 "School" channel with the subtopic name "Middle School". The publish at property has been set to publish the message at 1681324179000 Unix time.

pubsub_api_delayed_delivery