StompProtocolAndroid
StompProtocolAndroid copied to clipboard
need help : subscribe on topic not working
SocketUtils.instance.stompClient!!.topic("topic.58.rooms") .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe({ topicMessage -> println("topicMessage : ${topicMessage.payload}") //this block is not working }, { throwable -> throwable.printStackTrace() })
//code is written in kotlin response from server is coming, and being loggin in the logcat but not receiving in the above subscribe block.
Use this library its working fine in all use cases
https://github.com/SayyedUmar/Stomp-Android-Client
same problem occured with the library too, and it is the same library as this one @SayyedUmar
What error are you getting, share the source code if possible here?
On Wed, May 1, 2019, 10:21 LovepreetSinghLotey [email protected] wrote:
same problem occured with the library too, and it is the same library as this one @SayyedUmar https://github.com/SayyedUmar
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/NaikSoftware/StompProtocolAndroid/issues/145#issuecomment-488210176, or mute the thread https://github.com/notifications/unsubscribe-auth/ABV2UDFIBNKK4HVABI2Z4ITPTEOUDANCNFSM4HI6NGRQ .
I am using the latest Spring boot 2 & RabbitMQ. I also have this problem. Finally, I found that the problem is in "RabbitPathMatcher", The "path" and "dest" are different.
You may need to custom your own PathMatcher. My case is in "check3" solved.
`public class RabbitPathMatcher implements PathMatcher {
@Override
public boolean matches(String path, StompMessage msg) {
String dest = msg.findHeader(StompHeader.DESTINATION);
if (dest == null) return false;
// for example string "lorem.ipsum.*.sit":
// split it up into ["lorem", "ipsum", "*", "sit"]
String[] split = path.split("\\.");
ArrayList<String> transformed = new ArrayList<>();
// check for wildcards and replace with corresponding regex
for (String s : split) {
switch (s) {
case "*":
transformed.add("[^.]+");
break;
case "#":
// TODO: make this work with zero-word
// e.g. "lorem.#.dolor" should ideally match "lorem.dolor"
transformed.add(".*");
break;
default:
transformed.add(s.replaceAll("\\*", ".*"));
break;
}
}
// at this point, 'transformed' looks like ["lorem", "ipsum", "[^.]+", "sit"]
StringBuilder sb = new StringBuilder();
for (String s : transformed) {
if (sb.length() > 0) sb.append("\\.");
sb.append(s);
}
String join = sb.toString();
// join = "lorem\.ipsum\.[^.]+\.sit"
Boolean check1 = dest.matches(join);
//2nd check for same path
Boolean check2 = path.equals(dest);
//3rd check for last path e.g. (path : /exchange/amq.topic/100 , dest : /topic/100)
Boolean check3 = false;
if (transformed.size() > 0) {
String lastPath = transformed.get(transformed.size() - 1);
check3 = path.endsWith(lastPath);
}
return (check1 || check2 || check3);
}
} `
Are you sure that you subscribe to the sending topic as well? -
mStompClient.send("/topic/hello-msg-mapping", "My first STOMP message!").subscribe();