
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
ecc-messagebus
Advanced tools
ecc-messagebus
exports a normal rxmq.js instance but with a set of additional functions.
One of those functions is the createChannels
helper.
For convenience reasons it also exports Rx
so that we can use a fixed Rx
version in all components.
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
Request-response pattern can be used like so:
import rxmq from 'ecc-messagebus';
// ...
// get channel
const channel = rxmq.channel('yourChannel');
// subscribe to topic
channel.subject('someTopic').subscribe(({data, replySubject}) => {
// ...
// use envelop.reply to send response
replySubject.onNext({some: 'response'});
replySubject.onCompleted();
});
// ...
// initiate request and handle response as a promise
channel.request({
topic: 'someTopic',
data: {test: 'test'},
timeout: 2000
})
.subscribe((data) => {
// work with data here
// ...
},
(err) => {
// catch and handle error here
// ...
});
The createChannels
functions allows to define channels and subjects.
Basically it allows to create a channelDefinition with private and public subjects.
The Channel of Private Subjects can be changed.
This may sound counter-intuitive, but is actually a nice wrapper around changing channels.
This helper is predominantly used within the ecc-mixins
to create an event-bus per component instance,
so that there are no side effects (two components reacting on the same click handler)
// in a channelDefinition.js
import {createChannels, SubjectType} from 'ecc-messagebus'
const {privateChannel, publicChannel} = createChannels({
name: 'component',
subjects: {
secretMessage: SubjectType.private,
update: SubjectType.public,
}
});
export {privateChannel, publicChannel};
// in Component A
import {publicChannel, privateChannel} from './channelDefinition.js';
// Handle public messages
publicChannel.update.getSubject().subscribe(() => {
console.log('There was an update');
});
// Handle Secret Message from Component B
publicChannel.secretMessage.getSubject('secret-key-b').subscribe(() => {
console.log('Uuuuuh, a secret message from Component B');
});
// Handle Secret Message from Component C
publicChannel.secretMessage.getSubject('secret-key-c').subscribe(() => {
console.log('Uuuuuh, a secret message from Component C');
});
// in Component B
import {privateChannel} from './channelDefinition.js';
// Send to Component A on Secret Channel
publicChannel.secretMessage.getSubject('secret-key-b').onNext('pssst, component A');
// in Component C
import {privateChannel} from './channelDefinition.js';
// Send to Component A on Secret Channel
publicChannel.secretMessage.getSubject('secret-key-c').onNext('pssst, component A');
[3.6.0] 2016-06-24
rx@4.1.0
dependency, which is exported as Rx
rxmq
and rxmq.middleware
to be compatible with rx@4.1.0
FAQs
Eccenca Message Bus for inter-component and in-app communications.
We found that ecc-messagebus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.