2

I've added StompClientLib in my project and I'm facing problem while unsubscribing a destination topic.

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")

Yes, It's an issue with subscription name but It doesn't accept the same 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 unsubscribe replies me with an error: No subscription matched
Can anyone 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 the 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 javcScript (not an iOS - swift) code, a sample that available in this link (Subscribe and receive messages) and we implemented similar way it in web application:

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

The subscribe() methods return a JavaScript object 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. I don't get any value (destination subscription id) from subscription socketClient?.subscribe(destination: destinationChannelTopic) method

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

Please help to find out the solution for this problem.

Here is reference link about the issue: unsubscribe socketclient #14

2
  • It's not clear what library you are actually using when this problem occurs. You say you're using StompClientLib, but then you cite the documentation from the "stomp-websocket" Javascript library. Please clarify the role each of these libraries plays in your environment. Also, what version of the Stomp protocol are you using? Jan 28, 2018 at 14:49
  • Mention that the StompClientLib library is a swift wrapper for the "stomp-websocket" Javascript library Feb 12, 2018 at 5:39

2 Answers 2

7
+250

Subscription methodology approach for subscribe and unsubscribe are very different.

Subscribe uses unique destination (id) to connect with server as a destination but links and remembers it with reference of subscription-id and uses subscription-id to identify itself on server while unsubcribe.

Here is code, you are looking for. Try it.

let destination = "/topic/channel_1234"
let ack = "ack_\(destination)" // It can be any unique string
let subsId = "subscription_\(destination)" // It can be any unique string
let header = ["destination": destination, "ack": ack, "id": subsId]

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

// unsubscribe
socketClient?.unsubscribe(destination: subsId)
5

The subscribe func in this StompClientLib library is not returning the subscription ID that the server will generate and return to the client. You can see the code here:

https://github.com/WrathChaos/StompClientLib/blob/master/StompClientLib/Classes/StompClientLib.swift#L356

So you will have to specify a subscription ID by using this other func from the library, and provide a stomp header that includes a subscription ID of your choosing:

public func subscribeWithHeader(destination: String, withHeader header: [String: String])

For example:

var destination = "mytopic"
var ack = StompCommands.ackAuto
var subsId = "12345"
let header = [StompCommands.commandHeaderDestination: destination, StompCommands.commandHeaderAck: ack, StompCommands.commandHeaderDestinationId: subsId]
socketClient?.subscribeWithHeader(destination, header)
...
socketClient?.unsubscribe(subsId)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.