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:

NSString *message = @"Hello World!";

PublishOptions *publishOptions = [PublishOptions new];
[publishOptions addHeaderWithName:@"city" value:@"Tokyo"];

[Backendless.shared.messaging publishWithChannelName:@"default" message:message publishOptions:publishOptions responseHandler:^(MessageStatus *messageStatus) {
    NSLog(@"Message (id = %@) has been published with status: %@", messageStatus.messageId, messageStatus.status);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
let message = "Hello World!"

let publishOptions = PublishOptions()
publishOptions.addHeader(name: "city", value: "Tokyo")

Backendless.shared.messaging.publish(channelName: "default", message: message, publishOptions: publishOptions, responseHandler: { messageStatus in
    print("Message (id = \(messageStatus.messageId ?? "") has been published with status: \(messageStatus.status ?? "")")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")