Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eccenca/ecc-messagebus
Eccenca Message Bus for inter-component and in-app messaging
https://github.com/eccenca/ecc-messagebus
Last synced: about 1 month ago
JSON representation
Eccenca Message Bus for inter-component and in-app messaging
- Host: GitHub
- URL: https://github.com/eccenca/ecc-messagebus
- Owner: eccenca
- Created: 2016-05-12T11:25:08.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-02-06T07:41:24.000Z (almost 7 years ago)
- Last Synced: 2024-11-14T04:42:22.453Z (about 1 month ago)
- Language: JavaScript
- Size: 144 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 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
```js
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:
```js
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
// ...
});
```