stubber-heimdall-client
v1.0.0
Published
Library for interacting with Heimdall global events system
Downloads
32
Maintainers
Readme
Heimdall Client
Library to easily use the Heimdall global events system within a project
Installing the NPM Module
You need to be logged into NPM to use this private module.
npm login
npm install @satthief/heimdall-client --add
Quick Use
const heimdall = require('@satthief/heimdall-client');
//make a client to interact with
var hdc_config = {
'host':'192.168.113.15',
'user':'test',
'pass':'test'
};
heimdall.connect(hdc_config,function(err,hdc){
//Example trigger handler config - DYNAMIC QUEUE - Beware!
var handler_config_dynamic = {
'dynamic':true,
'topic':'example-heimdall-client-app',
'handler_function':function(data,cb){
console.log('handler got',data);
return cb();
}
};
//Example trigger handler config - STATIC QUEUE - Need to bind manually on RabbitMQ
var handler_config_static = {
'dynamic':false,
'queue':'my-manually-bound-queue',
'handler_function':function(data,cb){
console.log('handler got',data);
return cb();
}
};
//Example of registering for trigger on an event global.test.werner
var regtrigger = {
'uuid':'88888888-2343-2325-2523-888888888888',
'registration':{
"events": {
"test_event": {
"path": "global.test.werner",
"mechanism": "evt"
}
}
},
'trigger': {
"on_trigger": {
"default_deregister": true
},
"system": {
"type": "rabbitmq",
"exchange": "/exchange/ex-heimdall-triggers",
"topic": "example-heimdall-client-app",
"server": "mq01",
"data_method":"inject_into_triggerdata",
"triggerdata_inject_path":"eventdata_here",
},
"triggerdata": {
"eventdata_here": {
},
"test_trigger_obj":{
"bla":"dee"
}
}
}
};
//Example of an event to emit
var event = {
"path": "global.test.werner",
"mechanism":"evt",
"eventdata": {
"girl": "monalisa"
}
};
//Do all 3 actions in series - Callback method
hdc.setup_trigger_handler(handler_config,function(err){
console.log('Back from setup_trigger_handler');
hdc.register_trigger(regtrigger,function(err){
console.log('Back from register_trigger');
true ? hdc.emit_event(event,function(err){
console.log('Back from emit_event');
}) : false;
});
});
});
Notes and Links
Choose 1 of 2 methods for receiving triggers
explicit queue setup you setup a queue on RabbitMQ for your application and then bind the queue via a topic to ex-heimdall-triggers, then use this queue in your trigger handler config
dynamic queue you specify dynamic and a topic in the heimdall trigger handler config, this connects to RabbitMQ and makes a dynamic subscription, it is linked to the exchange
- disadvantages of this method are that when you disconnect the queue gets removed and triggers will go missing
- each instance of the app will have its own queue, duplicates are possible ??
- see more at https://www.rabbitmq.com/stomp.html#d.ed
Copyright Stucky-Solutions.net Werner Stucky All rights reserved