Repeated Publish¶
Backendless supports repeated message processing - a message is published once, but is delivered to subscribers with the specified frequency. Repeated delivery will stop either at the specified time unless it is canceled using the message cancellation API.
Blocking Publish¶
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.PublishAt = DateTime.Now.AddSeconds( 20 );
deliveryOptions.RepeatEvery = 20;
deliveryOptions.RepeatExpiresAt = DateTime.Now.AddHours( 1 );
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 - {status.MessageId}. Message Status - {status.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 );
deliveryOptions.RepeatEvery = 20;
deliveryOptions.RepeatExpiresAt = DateTime.Now.AddHours( 1 );
Backendless.Messaging.Publish( "This message was scheduled 20 seconds ago", deliveryOptions, callback );