-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from moleculerjs/issue-74
don't destroy consumer when there are pending messages
- Loading branch information
Showing
2 changed files
with
84 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
|
||
// Adapted from: https://github.com/moleculerjs/moleculer-channels/issues/74 | ||
|
||
const { ServiceBroker } = require("moleculer"); | ||
const ChannelsMiddleware = require("../../types").Middleware; | ||
const broker = new ServiceBroker({ | ||
namespace: "test", | ||
nodeID: "test1", | ||
transporter: "TCP", | ||
middlewares: [ | ||
ChannelsMiddleware({ | ||
adapter: "redis://127.0.0.1:6379" | ||
}) | ||
] | ||
}); | ||
|
||
const serviceSchema = { | ||
name: "subscriber", | ||
channels: { | ||
"order.created": { | ||
group: "mygroup", | ||
redis: { | ||
minIdleTime: 1000, | ||
claimInterval: 1, | ||
startID: "0" | ||
}, | ||
maxRetries: 100, | ||
handler(payload) { | ||
this.logger.info("Received order.created event", payload); | ||
throw new Error(); | ||
} | ||
} | ||
} | ||
}; | ||
broker.createService(serviceSchema); | ||
|
||
// Start the Moleculer broker | ||
broker.start().then(async () => { | ||
try { | ||
broker.repl(); | ||
|
||
for (let i = 0; i < 10; i++) { | ||
await broker.sendToChannel("order.created", { id: i, items: "test" }); | ||
|
||
await broker.Promise.delay(100); | ||
} | ||
|
||
await broker.destroyService("subscriber"); | ||
|
||
setTimeout(() => { | ||
broker.logger.info("Recreate service"); | ||
broker.createService(serviceSchema); | ||
}, 10000); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters