Cancel Scheduled Message¶
Delayed delivery as well as repeated publish messages can be canceled using the API documented below:
Non-blocking API¶
Backendless.Messaging.cancel( messageId ) .then( function( messageStatus ) { }) .catch( function( error ) { });
Blocking API¶
var messageStatus = Backendless.Messaging.cancelSync( messageId );
where:
Argument | Description |
---|---|
messageId |
ID of the message to cancel. Message ID must be obtained from the MessageStatus object returned in the result of the Publish method. |
Return value¶
Method returns messageStatus object with the following structure:
{ status : value, messageId: messageIdValue }
If the status
property is "cancelled"
, the cancellation has been successful.
Errors¶
The following errors may occur during the message cancellation API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error:
Error Code |
Description |
---|---|
5040 |
Message has already been canceled or does not exist. |
Example¶
Non-blocking Publish then Cancel¶
var channel = "TestChannel", message = "Hello, world!", pubOps = null; deliveryOps = new Backendless.DeliveryOptions({ publishAt: (new Date()).getTime() + 60 * 1000 // 1 minute delay }); Backendless.Messaging.publish( channel, message, pubOps, deliveryOps ) .then( function( messageStatus ) { Backendless.Messaging.cancel( response.messageId ); }) .catch( function( error ) { });
Blocking Publish then Cancel¶
var channel = "TestChannel", message = "Hello, world!", pubOps = null; deliveryOps = new Backendless.DeliveryOptions({ publishAt: (new Date()).getTime() + 60 * 1000 // 1 minute delay }); var response = Backendless.Messaging.publishSync( channel, message, pubOps, deliveryOps ); Backendless.Messaging.cancelSync(response.messageId);