hemerajs / hemera-nats-streaming Goto Github PK
View Code? Open in Web Editor NEWUse nats-streaming with Hemera
License: MIT License
Use nats-streaming with Hemera
License: MIT License
Sorry if this post comes out rude in any way, but we tried to use this plugin in our upcoming project (given that it's mentioned in the Hemera documentation) and it turned into hours of trying to make sense of the things that we were seeing in logs. When I finally went looking into the source code I was surprised to say the least, and still have no idea how it's supposed to be working with more than one service. I'll give an example to illustrate what I mean.
From what I gather, this plugin more or less works in the following way (please correct me if I'm wrong at any point):
For publishing:
natss
topic with publish
commandFor subscriptions:
hemera.natss.add
method is usednatss.event-subject
topic from a subscription handlernatss.subject
topicNow, let's imagine that we have 3 independent services, all using Hemera with Hemera-nats-streaming plugin. Let's call them A, B and C. An event with a subject user-created
is published by A, while B and C wish to subscribe to it.
hemera.natss.add({
subject: 'user-created'
})
and then add a handler via Hemera
hemera.add({ topic: 'natss.user-created' }, async () => { })
hemera.act({
topic: 'natss',
cmd: 'publish',
subject: 'user-created',
data: { }
})
At this point strange things start to happen:
I don't know why events are first passed through NATS with Hemera before being published in NATS streaming (is this a Hemera plugin limitation?), but since all services have handler on the same natss
topic, it gets routed to a randomly selected one, instead of the one that tries to emit an event in a first place.
At this point it still works correctly, even though the network traffic is doubled and it's very confusing to debug (for example, event handler error logs end up in random services).
Looking good at this point, every service received the event just as intended
natss.user-created
topicAt this point all hell breaks loose. We have two services listening on a topic natss.user-created
. This means that any of the following scenarios can happen, at random:
You can imagine how difficult it was to debug, given that it works correctly (though not efficiently) with a single listener for a given event, but breaks as soon as you add a second one and only get worse with more.
It seems less like a bug and more like a flaw in a way that a plugin is designed, so I don't know what the solution should be here. Things that comes to my mind are:
If it's possible to intercept Hemera in a way that would allow passing events in memory (both when publishing and subscribing) I think it would resolve most of the issues, but I don't know if Hemera allows it in a first place.
Hello,
I just realized that node-nats-streaming is fixed to 0.0.28 ( Semver fixes exact version for ^0.0.x
, ref: https://nodesource.com/blog/semver-tilde-and-caret/#caretmajorzero ). Can we safely update to 0.0.41 (latest released version)?. This would help solve nats-io/stan.js#73 among others.
Hello,
I'm trying to perform some tests using Jest.
Jest returned an error about open Handlers, and after some debugging it seems that a nats connection is left open.
I tried to check if there was a way to close nats connection inside hemera-nats-streaming, but it seems that the onClose handler does nothing:
https://github.com/hemerajs/hemera-nats-streaming/blob/master/index.js#L35
Shouldn't this function close the connection to nats server? Is there any other way to gracefully shutdown the connection?
Error when use plugins in hemera, ERR_AVVIO_PLUGIN_TIMEOUT: plugin did not start in time.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.