Problems with PUBSUB - PatternNotFound
OsoianMarcel opened this issue · comments
Description
Problem with PUBSUB:
No handler found for this pattern (PatternNotFound)
Steps to Reproduce
server.js
const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});
hemera.ready(() => {
// Add service command
hemera.add({topic: 'service', cmd: 'do'}, (req, cb) => {
cb(null, {result: 'ok! done! - ' + req.data});
// Emit an event (one-to-many)
hemera.act({
pubsub$: true,
topic: 'service',
cmd: 'event',
payload: 'add was executed!'
});
});
// Subscribe to "topic:payment,cmd:event"
hemera.add({pubsub$: true, topic: 'service', cmd: 'event'}, req => {
console.log('event', req);
});
});
subscriber.js
const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});
hemera.ready(() => {
// TODO: Check the problem here
// Subscribe to "topic:payment,cmd:event"
hemera.add({pubsub$: true, topic: 'service', cmd: 'event'}, req => {
console.log('event', req);
});
});
client.js
const Hemera = require('nats-hemera');
const nats = require('nats').connect();
const hemera = new Hemera(nats, {logLevel: 'error'});
hemera.ready(() => {
// Call service command "topic:service,cmd:do"
hemera.act({topic: 'service', cmd: 'do', data: 123}, (err, resp) => {
console.log(err, resp);
});
});
Steps to Reproduce
1. Start server.js (no output)
node server.js
2. Start subscriber.js (no output)
node subscriber.js
3. Start client.js
node client.js
Output (expected output):
null { result: 'ok! done! - 123' }
4. Now check subscriber.js output (PROBLEM)
Expected Result
Expected subscriber.js output:
event { topic: 'service', cmd: 'event', payload: 'add was executed!' }
Actual Result
Actual subscriber.js result (ERROR):
[2017-07-12T11:49:17.033Z] ERROR (hemera-ff254d962b06-fd3d138ee7f34f5181357a5ba2bfc9e1/765 on ff254d962b06): No handler found for this pattern
PatternNotFound
at Hemera._onServerPreRequestHandler (/code/node_modules/nats-hemera/lib/index.js:835:29)
at ctx._extensions.onServerPreRequest.dispatch (/code/node_modules/nats-hemera/lib/index.js:876:74)
at done (/code/node_modules/nats-hemera/lib/util.js:155:15)
at Hemera.onServerPreRequestLoadTest (/code/node_modules/nats-hemera/lib/extensions.js:214:3)
at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
at done (/code/node_modules/nats-hemera/lib/util.js:153:15)
at Hemera.onServerPreRequest (/code/node_modules/nats-hemera/lib/extensions.js:192:3)
at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
[2017-07-12T11:49:17.039Z] ERROR (hemera-ff254d962b06-fd3d138ee7f34f5181357a5ba2bfc9e1/765 on ff254d962b06): No handler found for this pattern
PatternNotFound
at Hemera._onServerPreRequestHandler (/code/node_modules/nats-hemera/lib/index.js:835:29)
at ctx._extensions.onServerPreRequest.dispatch (/code/node_modules/nats-hemera/lib/index.js:876:74)
at done (/code/node_modules/nats-hemera/lib/util.js:155:15)
at Hemera.onServerPreRequestLoadTest (/code/node_modules/nats-hemera/lib/extensions.js:214:3)
at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
at done (/code/node_modules/nats-hemera/lib/util.js:153:15)
at Hemera.onServerPreRequest (/code/node_modules/nats-hemera/lib/extensions.js:192:3)
at each (/code/node_modules/nats-hemera/lib/extension.js:65:14)
at iterate (/code/node_modules/nats-hemera/lib/util.js:160:9)
event { topic: 'service', cmd: 'event', payload: 'add was executed!' }
**Very important: ** Subscriber recevied the event, but with errors.
Context
- nats-hemera (core)
Your Environment
- NATS: 0.9.6 (server version)
- Hemera: 1.3.12
- NodeJs: v8.1.2
- Environment name and version: no env. name
- Operating System and version: Docker (MacOS), Images: node:alpine, nats:latest
Hi @OsoianMarcel this behaviour is correct because you can't start multiple services with the same topic and different implemenation. The publisher is not aware of that because the request is load balanced between them. If you call to a service topic:service
that service has to contain the full implementation doesnt matter where it lives.
You can create other services if you assign a unique topic name. The topic
is the smallest unit in hemera.
Refer to your example:
Server.js and Subscriber.js share the same topic service
but dont implement the full contract
{topic: 'service', cmd: 'do'}
{pubsub$: true, topic: 'service', cmd: 'event'}
when the request arrives NATS, NATS cant know that therefore No handler could be found