Closed chrvadala closed 6 years ago
I found a better way to replicate this issue.
serviceA.js
and serviceB.js
)# node serviceA.js
# node serviceB.js
# node serviceA.js
Now you can see that service B can't contact serviceA Hope that this way can help you.
serviceA.js
const {ServiceBroker} = require("moleculer");
let brokerA = new ServiceBroker({nodeID: "serviceA", transporter: "mqtt://localhost:1883"})
brokerA.createService({
name: "serviceA",
async stopped() {
this.logger.info('pre - stop')
await new Promise(resolve => setTimeout(resolve, 1000))
this.logger.info('post - stop')
},
actions: {
sayHi() {
this.logger.info("hi")
}
}
})
brokerA.start()
serviceB.js
const {ServiceBroker} = require("moleculer");
let brokerB = new ServiceBroker({nodeID: "serviceB", transporter: "mqtt://localhost:1883"})
brokerB.createService({
name: "serviceB",
started() {
this.timer = setInterval(() => {
this.broker.call('serviceA.sayHi')
.then(() => this.logger.info('OK'))
.catch(() => this.logger.error('FAIL'))
}, 1000)
},
stopped() {
clearTimeout(this.timer)
},
})
brokerB.start()
Thanks, I could reproduce. However, it works well with other transporters, except MQTT.
Fixed. MQTT client should wait for the in-flight messages (DISCONNECT) before closing the connection.
Just tested and it works very well. Thanks!
Hi Icebob, I've just found a strange behaviour with a service that I gracefully stop and then restart. It seems that when the service goes up the second time the DISCOVER packet is ignored by others. As result, every other node can't call service actions served by this restarted service.
I use MQTT as transport I use the
async stopped()
hook that resolves after 5 secondsI noticed that without a pause by few seconds on stop, the service doesn't have enough time to send its disconnect message. But this is related with https://github.com/moleculerjs/moleculer/issues/306.
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Expected Behavior
When the service is restarted actions should be correctly available again.
Current Behavior
After a service restart actions aren't available
Steps to Reproduce
moleculer-cli
on the same brokeractions
on moleculer cli (actions are available)actions
on moleculer cli (actions aren't available)Reproduce code snippet
NODEID=test2 TRANSPORTER=mqtt LOGLEVEL=debug ./node_modules/.bin/moleculer-runner test2.service.js
Failure Logs
The log seems good