Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wild card subscriptions don't work #1

Closed
karlp opened this issue Mar 25, 2010 · 4 comments
Closed

wild card subscriptions don't work #1

karlp opened this issue Mar 25, 2010 · 4 comments

Comments

@karlp
Copy link

karlp commented Mar 25, 2010

I'll see if I can fix this myself, but just so you know...
If I do..
client.subscribe("/topic/karlnet.>", onreceive);

Then the debug clearly shows that the messages are received, but the

var onreceive = subscriptions[frame.headers.destination];
if (onreceive) {

lines, look for an exact match, which isn't found.

@jmesnil
Copy link
Owner

jmesnil commented Mar 26, 2010

yes, I did not implement wild card subscription as they're dependent on the Stomp broker you use (I suppose you're using ActiveMQ, right?)

we could create a mapper function which returns a boolean if the frame.headers.destination matches the destination used when subscribing and loop on the subscriptions to find which ones match the destinations.
This mapper function would be passed as an optional parameter when creating the Stomp.client.
By default, this will be a straight mapping (with exact match) and we'd include another mapper for ActiveMQ (they probably already have a JavaScript function which does that in their codebase)

Do you have another idea how you want to fix this?

@jmesnil
Copy link
Owner

jmesnil commented Mar 26, 2010

actually, I think we can support wildcard without much work.

Stomp specified that when a client SUBSCRIBE to a destination and pass an id header, all messages received by the subscriber will have this id[1].
In client.subscribe, we can generate an id:

that.subscribe = function(destination, callback, headers) {
var headers = headers || {};
var id = // generate id
headers.destination = destination;
headers.id = id;
subscriptions[id] = callback;
transmit("SUBSCRIBE", headers);
};

When a message is received, we will check for this id instead of the destination header:

  } else if (frame.command === "MESSAGE") {
    var onreceive = subscriptions[frame.headers.id];
    if (onreceive) {
      onreceive(frame);
    }
  } 

This only thing I am not sure is the uniqueness of the id.
Can it be unique for the given Stomp client (and a counter is enough) or among all clients connected to a Stomp broker (and we'd have to use a UUID instead)

Interested to contribute? :)

[1] http://activemq.apache.org/stomp/stomp10/specification.html#subscribe

@karlp
Copy link
Author

karlp commented Mar 26, 2010

My reading of that would be that it must be per client. Otherwise the broker is forcing the client to know about all other clients, (or at least, choose an id that is required never to clash with any other client, current or future) Given that the client provides the ID, it must be safe to assume that the id is the id in the client system, not the id in the broker system.

I'll get to this eventually (probably) but it won't be for at least a week, and my jsfu is barely beginning.

@jmesnil
Copy link
Owner

jmesnil commented Mar 26, 2010

Wildcard subscriptions support

  • add a id header when subscribing to a destination and
    find the corresponding onreceive handling by looking at the message's subscription header
  • subscribers are unique for a given Stomp.client (incrementing its counter field)

closed by 394663d

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants