Publish with 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.
The following example publishes a message with the city : Tokyo
header:
Blocking Publish¶
PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "city", "Tokyo" );
Weather weather = new Weather();
weather.Humidity = 80;
weather.Temperature = 78;
MessageStatus status = Backendless.Messaging.Publish( weather, publishOptions );
System.Console.WriteLine( $"Message published. Message ID - {status.MessageId}. Message Status - {status.Status}" );
Non-blocking Publish¶
AsyncCallback<MessageStatus> callback = new AsyncCallback<MessageStatus>(
result =>
{
System.Console.WriteLine( $"Message published. Message ID - {result.MessageId}. Message Status - {result.Status}" );
},
fault =>
{
System.Console.WriteLine( "Error - " + fault );
} );
PublishOptions publishOptions = new PublishOptions();
publishOptions.AddHeader( "city", "Tokyo" );
Weather weather = new Weather();
weather.Humidity = 80;
weather.Temperature = 78;
Backendless.Messaging.Publish( weather, publishOptions, callback );