Hello
I ‘m getting error when trying to subscribe to channel The error code is 5009 and the message ’ error during subscription ’
Maybe that’s because of the query in the selector … But I’m sure it’s right … that’s the code :
final SubscriptionOptions options = new SubscriptionOptions();
StringBuilder selector = new StringBuilder();
selector.append(“from = '”).append(name).append("’")
.append(" AND to: = ‘").append(current_name).append("’");
selector.append(" OR from = ‘").append(current_name).append("’");
selector.append(" AND to: = ‘").append(name).append("’");
options.setSelector(selector.toString());
Backendless.Messaging.subscribe(“privateChat”, new AsyncCallback<List<Message>>() { @Override
public void handleResponse(List<Message> messages) {
} @Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(privateChat.this,backendlessFault.toString(),Toast.LENGTH_SHORT).show();
}
},options, new AsyncCallback<Subscription>() { @Override
public void handleResponse(Subscription subscription) {
Toast.makeText(privateChat.this,“subscribed”,Toast.LENGTH_SHORT).show();
} @Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(privateChat.this,backendlessFault.toString()+ backendlessFault.getMessage()+ backendlessFault.getDetail()+backendlessFault.getCode(),Toast.LENGTH_SHORT).show();
}
});
And thanks
Hello!
You have mistakes in the selector: remove “:” after words “to” in the following rows:
.append(" AND to: = ‘").append(current_name).append("’");
…
selector.append(" AND to: = ‘").append(name).append("’");
it worked ! Thank you Alexandr, Mark
But please I have a question : if I subscribed to a channel but the channel is empty or there isn’t any messages … The code in handle response run or what ?
when I send message to “privateChat” channel , the code in the subscribe call should run right ? I mean after subscribe to channel , It will return the list of messages in the channel . but if there isn’t any messages it will wait until new message is published then it will run … but why my code in handleResponse isn’t running even if a user send message to the channel ?it’s because selector ? but I’m sure the SQL query is work ! I’ll post my code soon
and thanks for supporting me ! your support section is really helpful (y)
final SubscriptionOptions options = new SubscriptionOptions();
StringBuilder selector = new StringBuilder();
selector.append("from = '").append(name).append("'")
.append(" AND to = '").append(current_name).append("'");
selector.append(" OR from = '").append(current_name).append("'");
selector.append(" AND to = '").append(name).append("'");
options.setSelector(selector.toString());
Backendless.Messaging.subscribe("privateChat", new
AsyncCallback<List<Message>>() {
@Override
public void handleResponse(List<Message> messages) {
get();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {}
}, options, new AsyncCallback<Subscription>() {
@Override
public void handleResponse(Subscription subscription) {
get();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {}
});
when A new message is published … the code in the AsyncCallBack<List<Message>> isn’t running