Skip to content

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:

// do not forget to call Backendless.initApp in the app initializatio logic

PublishOptions publishOptions = new PublishOptions();
publishOptions.putHeader( "city", "Tokyo" );
Weather weather = new Weather();
weather.setHumidity( 70 );
weather.setTemperature( 80 );
Backendless.Messaging.publish( weather, publishOptions, new AsyncCallback<MessageStatus>()
{
  @Override
  public void handleResponse( MessageStatus response )
  {
     Log.i( "MYAPP", "message has been published" );
  }

  @Override
  public void handleFault( BackendlessFault fault )
  {
     Log.e( "MYAPP", "Server reported an error " + fault );
  }
} );