Introduction¶
In order to receive published messages, application must subscribe to a channel. The subscription API returns a Channel
object which can be used to add messaging callbacks. A callback is used by Backendless to deliver published messages to the client application.
Consider the following example, which demonstrates subscribing to a channel and adding a messaging callback:
final Channel channel = Backendless.Messaging.subscribe( "chat" );
AsyncCallback<String> callback = new AsyncCallback<String>()
{
@Override
public void handleResponse( String chatMessage )
{
System.out.println( "got a message " + chatMessage );
}
@Override
public void handleFault( BackendlessFault fault )
{
System.out.println( "got error " + fault );
}
};
channel.addMessageListener( callback );