Comments (9)
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.
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.
Maybe You meant it:
if (typeof topic === 'string' || topic instanceof RegExp) {
?
from hemera.
@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.
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?
- Since topic for add is a full-wildcard token, then it tranclated to RegExp, here:
hemera/packages/hemera/lib/index.js
Line 1104 in d13b529
And this RegExp object set tothis._topics
Map registry as key, here
hemera/packages/hemera/lib/index.js
Line 1146 in d13b529
- When calling of
hemera.close
it will makeremoveAll
subscriptions, here:
hemera/packages/hemera/lib/index.js
Line 1532 in d13b529
- Finally, it call
remove
function with RegExp object as topic argument.
hemera/packages/hemera/lib/index.js
Line 1533 in d13b529
from hemera.
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.
You're welcome. Sorry, I have no time :( You can?
from hemera.
mcollina/bloomrun#48 (comment)
from hemera.
Closed in #236
from hemera.
Related Issues (20)
- Logging id HOT 15
- Direct communication ? HOT 3
- stats plugin not returning all actions HOT 7
- Does hemera.close() killall running jobs? HOT 2
- TypeError when defining custom Pino logger HOT 1
- Why https://hemerajs.github.io/hemera/docs/reference.html contains not documentation for add() function. HOT 3
- Adding hemera to Docusaurus users page HOT 3
- Unable to subscribe to NATS topic when the publisher is not running on Hemera HOT 1
- Client Timeout HOT 3
- hemera-ajv doesnt seem to be working correctly HOT 4
- Hemera-blipp has old hemera version HOT 3
- Have you looked into ts-nats? HOT 3
- How to reply from middleware or extension? HOT 5
- Looking for maintainers and collaborators HOT 5
- NATS disconnection question HOT 1
- Calling reply.send inside async middleware doesn't stop the chain HOT 2
- Typescript support HOT 1
- hemera-zipkin package missing HOT 3
- Any way to unregister an extension? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hemera.