Eccenca Message Bus for inter-component and in-app communications
ecc-messagebus
exports a normal rxmq.js instance but with a set of additional functions.
For convenience it also exports Rx
so that we can use a fixed Rx
version in all components.
Using Rx
import {Rx} from 'ecc-messagebus';
var source = Rx.Observable.just(42);
var subscription = source.subscribe(
function (x) {
console.log(`Next: ${x}');
},
function (err) {
console.log(`Error: ${err}`);
},
function () {
console.log('Completed');
});
// => Next: 42
// => Completed
Using request-response
Request-response pattern can be used like so:
import rxmq from 'ecc-messagebus';
const channel = rxmq.channel('yourChannel');
channel.subject('someTopic').subscribe(({data, replySubject}) => {
replySubject.onNext({some: 'response'});
replySubject.onCompleted();
});
channel.request({
topic: 'someTopic',
data: {test: 'test'},
timeout: 2000
})
.subscribe((data) => {
},
(err) => {
});