@ciklum/xmess-repeater
v0.1.1
Published
XMESS plugin for repeating messages among few XMESS instances
Downloads
1
Readme
XMESS Repeater
XMESS plugin for repeating messages among few XMESS instances
Table of contents
Description
XMESS Repeater - module which provides functionality of binding/communication among many XMESS instances. Usualy we use only one XMESS instance on app, but when we works with multiple applications then can use repeater for communication among them.
Usage
Set private repository:
npm config set registry https://registry.npmjs.org/:_authToken=5ea6cd25-4d7d-4def-9ae0-e09c52e5b9a5
Install XMESS Repeater:
npm install @ciklum/xmess-repeater --save
Import
XmessRepeater
to fileimport { XmessRepeater } from '@ciklum/xmess-repeater'; ...
Construct
XmessRepeater
withtranslatorId
andrepeaterCallback
import { XmessRepeater } from '@ciklum/xmess-repeater'; import { Xmess } from '@ciklum/xmess'; const xmess = new Xmess(); const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => { xmess.publish(path, payload) }); xmess.onPublish((path, payload) => { xmessRepeater.publish(path, payload); }) ...
API
.publish(path, payload)
for to subscribed XMESS`s, wherepath
is channelName andpayload
is data for publishingimport { XmessRepeater } from '@ciklum/xmess-repeater'; const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => { ... }); xmessRepeater.publish('app-group/route:changed', { pathname: '/offer' }) ...
.getMessage(path)
for getting last message from channel by pathimport { XmessRepeater } from '@ciklum/xmess-repeater'; const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => { ... }); const message = xmessRepeater.getMessage('app-group/route:changed'); // message = { pathname: '/offer' } ...
.destroy()
for remove repeater instanceimport { XmessRepeater } from '@ciklum/xmess-repeater'; const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => { ... }); xmessRepeater.destroy() ...