Skip to content

Instantly share code, notes, and snippets.

@adamvr
Last active December 18, 2015 01:48
Show Gist options
  • Save adamvr/5706425 to your computer and use it in GitHub Desktop.
Save adamvr/5706425 to your computer and use it in GitHub Desktop.
mqttjs recovery after exception
node_modules
{
"name": "throw-test",
"version": "0.0.0",
"description": "",
"main": "throw.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/5706425.git"
},
"author": "",
"license": "BSD",
"gitHead": "1f645c87a8bca69135073d97922254d67f25b9d9",
"bugs": {
"url": "https://gist.github.com/5706425"
},
"dependencies": {
"mqtt": "~0.2.9"
}
}
var mqtt = require('mqtt');
var server = mqtt.createServer(function (client) {
client.on('connect', function(packet) {
client.connack({returnCode: 0});
client.publish({topic: 'herp', payload: 'derp'});
});
client.on('publish', function(packet) {
client.puback({messageId: packet.messageId});
});
});
server.listen(1884);
var client = mqtt.createConnection(1884);
client.on('connected', function() {
client.connect({
clientId: 'herpderp',
keepalive: 3000,
protocolId: 'MQIsdp',
protocolVersion: 3
});
client.on('connack', function(packet) {
client.publish({
topic: 'derp',
payload: 'herp',
messageId: 10,
qos: 1
});
});
client.on('publish', function(packet) {
console.dir(packet);
throw new Error('error!');
});
client.on('puback', function (packet) {
console.dir(packet);
});
});
client.stream.on('readable', function() {
console.log('readable!');
});
process.on('uncaughtException', function(err) {
console.log(err);
console.log('continue');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment