Git Product home page Git Product logo

Comments (9)

StarpTech avatar StarpTech commented on June 21, 2024

Hi @vdakalov

There wrote "if topic is string then take sid by its topic" but "else unsubscribe by topic which does not is string". And if topic is not a string, then it is a RegExp object. Result:

Where did you read it?

RegExp aren't supported only the topic or the subscription-id.

from hemera.

vdakalov avatar vdakalov commented on June 21, 2024

Here! And keep in mind topic is /^[a-zA-Z0-9-.]+$/i, because my topic (in hemera.add) is wildcard >

    // when sid was passed
    if (typeof topic === 'string') {
      // when topic name was passed
      const subId = self._topics.get(topic)

      if (subId) {
        self._transport.unsubscribe(subId, maxMessages)
        // we remove all subscription related to this topic
        this.cleanTopic(topic)
        return true
      }
    } else {
      self._transport.unsubscribe(topic, maxMessages)
      return true
    }

typeof topic === 'string' is false and execute else-branch. Then nats.unsubscribe(/^[a-zA-Z0-9-.]+$/i). And finally I see it in gnatsd output

[11605] 2018/11/20 14:02:39.579853 [TRC] 127.0.0.1:50742 - cid:1 - ->> [UNSUB /^[a-zA-Z0-9-.]+$/i]

from hemera.

vdakalov avatar vdakalov commented on June 21, 2024

Maybe You meant it:

    if (typeof topic === 'string' || topic instanceof RegExp) {

?

from hemera.

StarpTech avatar StarpTech commented on June 21, 2024

@vdakalov forget what I said. We can't use a RegexExp as a NATS subject. Here you can find all possible variants https://nats.io/documentation/internals/nats-protocol/.

Would you mind to create a PR which throws an error when no string or number was passed?

from hemera.

vdakalov avatar vdakalov commented on June 21, 2024

Let me describe steps for reproduce the problem here (PR will be unnecessary)

First, you need start nats server with trace option

gnatsd --trace

Next just execute follow script

import * as nats from 'nats';
import * as Hemera from 'nats-hemera';

const hemera = new Hemera(nats.connect(), {});
hemera.ready(() => {
 // add new subscription
  hemera.add({
    topic: '>' // <--- full wildcard topic
  }, (request, callback) => callback(null, 'Cut the Rope'));
  // send request
  hemera.act({
    topic: 'UndefinedTopic' // <--- this topic does not exist
  }, (error, response) => {
    console.log('Who are you: ' + response)
    hemera.close(); // <-- REQUIRED!
  });
});

Now look trace logs

...
[923] 2018/11/21 08:19:42.207369 [TRC] 127.0.0.1:55560 - cid:1 - ->> [UNSUB /^[a-zA-Z0-9-.]+$/i]
...

What happen?

  1. Since topic for add is a full-wildcard token, then it tranclated to RegExp, here:
    addDefinition.pattern.topic = Util.natsWildcardToRegex(patternOnly.topic)

    And this RegExp object set to this._topics Map registry as key, here
    this._topics.set(addDefinition.pattern.topic, sid)
  2. When calling of hemera.close it will make removeAll subscriptions, here:
    for (var topic of this._topics.keys()) {
  3. Finally, it call remove function with RegExp object as topic argument.
    this.remove(topic)

from hemera.

StarpTech avatar StarpTech commented on June 21, 2024

Hi @vdakalov thanks for the nice explanation. RegExp must be handled differently in comparison and if we want to remove it from the index. The PR is still needed. Would you like to create one?

from hemera.

vdakalov avatar vdakalov commented on June 21, 2024

You're welcome. Sorry, I have no time :( You can?

from hemera.

vdakalov avatar vdakalov commented on June 21, 2024

mcollina/bloomrun#48 (comment)

from hemera.

StarpTech avatar StarpTech commented on June 21, 2024

Closed in #236

from hemera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.