WrathChaos / StompClientLib

Simple STOMP Client library, Swift 3 and 4, 4.2, 5 compatible
https://www.freakycoder.com
MIT License
154 stars 81 forks source link

unsubscribe socketclient #14

Closed krunalbhavsar closed 6 years ago

krunalbhavsar commented 6 years ago

socketClient?.unsubscribe(destination: "destination string is same as subscribe destination string")

Unsubscription of destination gives following error:

"org.apache.activemq.transport.stomp.ProtocolException: No subscription matched.\r\tat org.apache.activemq.transport.stomp.ProtocolConverter.onStompUnsubscribe(ProtocolConverter.java:734)\r\tat org.apache.activemq.transport.stomp.ProtocolConverter.onStompCommand(ProtocolConverter.java:262)\r\tat org.apache.activemq.transport.ws.AbstractStompSocket.processStompFrame(AbstractStompSocket.java:151)\r\tat org.apache.activemq.transport.ws.jetty9.StompSocket.onWebSocketText(StompSocket.java:96)\r\tat org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextMessage(JettyListenerEventDriver.java:128)\r\tat org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69)\r\tat org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:64)\r\tat org.eclipse.jetty.websocket.common.events.JettyListenerEventDriver.onTextFrame(JettyListenerEventDriver.java:122)\r\tat org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:160)\r\tat org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:309)\r\tat org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:214)\r\tat org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220)\r\tat org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:258)\r\tat org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:628)\r\tat org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:476)\r\tat org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)\r\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\r\tat org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)\r\tat java.lang.Thread.run(Unknown Source)\r")

WrathChaos commented 6 years ago

Hello @krunalbhavsar, This is not an issue about StompClientLib. As you can see, it says the error: No subscription matched. Please check your topic names :) Have fun!

krunalbhavsar commented 6 years ago

Yes, It's an issue with subscription name but It doesn't accept the same string string I used to subscribe specific channel.

For example:

// destination
let destinationChannelTopic = "/topic/channel_1234"

// subscribe successful
socketClient?.subscribe(destination: destinationChannelTopic)

// unsubscribe not successful with same destination
socketClient?.unsubscribe(destination: destinationChannelTopic)

Here unsubcribe responds me an error: No subscription matched Can you please help me to understand, what is wrong? What am I doing wrong?

As I analyzed from Subscribe and receive messages, subscription (a subscribe method) returns a string (subscription channel id) from server, that we need to store somewhere at client side (in our project/code) and we need to use the same string to unsubscribe.

This is not an iOS (swift) code but a sample that available in above link and we implemented in web application:

// subscribe
var subscription = client.subscribe("/queue/test", callback);

The subscribe() methods returns a JavaScript obect with 1 attribute, id, that correspond to the client subscription ID and one method unsubscribe() that can be used later on to unsubscribe the client from this destination.

// unsubscribe
subscription.unsubscribe();

So, is this only the method/possible way, for subscription and unsubscription. If yes, then we do not have any value returning to subscribe(...) that I can use to unsubscribe.

Can you please provide a sample code block, guiding me, how can I successfully unsubscribe from destination topic. I've almost implemented this library 'StompClientLib' in my project and everything works fine except 'unsubcribe'.

As an alternate solution to this issue, I disconnect client from server and reconnect again + subscribe all other destinations again. And this is not a proper way to handle but I have only this solution at this time.

Thanks you for your response. Please help to find out solution for this problem.

Krunal

WrathChaos commented 6 years ago

@krunalbhavsar Hello again, Have you checked that can you subscribe correctly? If you cannot subscribe, you cannot unsubscribe either. If you need an example, please check the Example on the github. Example

krunalbhavsar commented 6 years ago

With this code, I can subscribe correctly.

// destination
let destinationChannelTopic = "/topic/channel_1234"

// subscribe successful
socketClient?.subscribe(destination: destinationChannelTopic)

But when I try to unsubscribe, using the same destination string, it replies with an error.

// unsubscribe not successful with same destination
socketClient?.unsubscribe(destination: destinationChannelTopic)

:( Don't know, what's wrong here.... in this code. Everything according to sample code.

krunalbhavsar commented 6 years ago

Here I found a proper (working) solution: https://stackoverflow.com/questions/48472473/stompclientlib-unsubscribe-socketclient/48769453#48769453

let destination = "/topic/channel_1234"
let ack = destination 
let subsId = destination
let header = ["destination": destination, "ack": ack, "id": subsId]

// subscribe
socketClient?.subscribeWithHeader(destination: destination, withHeader: header)

// unsubscribe
socketClient?.unsubscribe(destination: subsId)
WrathChaos commented 6 years ago

@krunalbhavsar I'm glad to find the working solution. I will add it to the ReadME part. Thank you so much :)