Skip to content
Browse files

added ensureTeardown flag

  • Loading branch information...
1 parent b258184 commit e95d5626ca1c9b2e3cf3002f7e9f86966609a159 @pelger committed
View
1 README.md
@@ -44,3 +44,4 @@ node hello.js
```
Run three copies to read messages from each of the three partitions.
+
View
21 lib/microbial.js
@@ -102,7 +102,8 @@ module.exports = function(options) {
topics = [topics];
}
- registerTopics(0, topics, function() {
+ registerTopics(0, topics, function(err) {
+ if (err) { return cb(err); }
load(services);
cb(null);
});
@@ -157,6 +158,7 @@ module.exports = function(options) {
*/
var register = function(topic, cb) {
_cfg.register(topic.group, topic.topicName, function(err, slot){
+ if (err) { return cb(err); }
if (!_options.start || _options.start === 'all') {
_kernel.register(topic, slot, function() {
cb(err, slot);
@@ -219,12 +221,19 @@ module.exports = function(options) {
- process.on('exit', tearDown.bind());
- process.on('SIGINT', function() {
- tearDown(function() {
- process.exit(0);
+ if (options.ensureTeardown) {
+ process.on('uncaughtException', function() {
+ tearDown(function() {
+ console.trace();
+ process.exit(1);
+ });
+ });
+ process.on('SIGINT', function() {
+ tearDown(function() {
+ process.exit(0);
+ });
});
- });
+ }
View
3 package.json
@@ -29,7 +29,8 @@
"axon": "~1.0.0",
"prozess": "~0.6.4",
"kafkaesque": "0.0.9",
- "node-zookeeper-client": "~0.2.1"
+ "node-zookeeper-client": "~0.2.1",
+ "uuid": "~1.4.1"
},
"main": "lib/microbial",
"repository": {
View
18 samples/hello/config/config.js
@@ -14,19 +14,11 @@ mcb.setup(function(err) {
console.log(JSON.stringify(config, null, 2));
mcb.writeConfig(config, function(err) {
- mcb.deregisterAll('hello', 'request', function() {
- mcb.deregisterAll('hello', 'response', function() {
- mcb.deregisterAll('goodbye', 'request', function() {
- mcb.deregisterAll('canonicalProducer', 'response', function() {
- mcb.tearDown();
- if (err) {
- console.log(err);
- }
- console.log('done');
- });
- });
- });
- });
+ mcb.tearDown();
+ if (err) {
+ console.log(err);
+ }
+ console.log('done');
});
}
else {
View
35 samples/hello/config/reset.js
@@ -0,0 +1,35 @@
+'use strict';
+
+var options = { zkroot: 'localhost:2181', namespace: 'canon', start: 'config' };
+
+var mcb = require('microbial')(options);
+
+mcb.setup(function(err) {
+ if (!err || (err && err.name && err.name === 'config_block_not_available')) {
+ console.log('updating config');
+ var config = mcb.blankConfig();
+ mcb.addBrokerToConfig(config, 'localhost', 9092, 2000000);
+ mcb.addTopicToConfig(config, 'request', 'queue', 3, 'roundRobin');
+ mcb.addTopicToConfig(config, 'response', 'queue', 3, 'direct');
+
+ console.log(JSON.stringify(config, null, 2));
+ mcb.deregisterAll('hello', 'request', function() {
+ mcb.deregisterAll('hello', 'response', function() {
+ mcb.deregisterAll('goodbye', 'request', function() {
+ mcb.deregisterAll('canonicalProducer', 'response', function() {
+ mcb.tearDown();
+ if (err) {
+ console.log(err);
+ }
+ console.log('done');
+ });
+ });
+ });
+ });
+ }
+ else {
+ console.log(err);
+ }
+});
+
+
View
2 samples/hello/services/goodbye.js
@@ -1,6 +1,6 @@
'use strict';
-var options = { zkroot: 'localhost:2181', namespace: 'canon', start: 'all' };
+var options = { zkroot: 'localhost:2181', namespace: 'canon', start: 'all', ensureTeardown: true };
var mcb = require('microbial')(options);
var goodbye = function(req, res) {
View
4 samples/hello/services/hello.js
@@ -1,7 +1,7 @@
'use strict';
-var options = { zkroot: 'localhost:2181', namespace: 'canon', start: 'all' };
-var mcb = require('microbial')(options);
+var options = { zkroot: 'localhost:2181', namespace: 'canon', start: 'all', ensureTeardown: true };
+var mcb = require('../../../')(options);
var whatever = function(req, res) {

0 comments on commit e95d562

Please sign in to comment.
Something went wrong with that request. Please try again.