Package provides RxmqService that is a wrapper for Rxmq message broker.
RxmqService provides channel, registerChannelPlugin and registerPlugin methods which corresponds with Rxmq methods
and requestResponseChannel which return RequestResponseChannel.
ngx-rxmq provide a MQable interface.
interface MQable {
connect(mq: RxmqService): void;
}
It should be used in service provided as arguments for forRoot and forFeature static methods of NgxRxmqModule.
On provided service connect method will be called with RxmqService as argument. Instances of this services will be created at start up
of application (forRoot) or on load of a feature module (forFeature).
Usage
Basic usage
Import NgxRxmqModule.forRoot() in AppModule. For feature modules (lazy loaded) import per module NgxRxmqModule.forFeature()
Service DemoAService and DemoBService will be created at startup of application. There is not need to inject this services to
component if this services only listen to message queue and act base on event passed to queue eg. side effects, http requests.
For feature modules:
@NgModule({
imports:[
...
NgxRxmqModule.forFeature([FeatureAService]),
...
],
declarations:[FeatureAComponent]
})
exportclassFeatureAModule{}
Feature service:
@Injectable({
providedIn:'root'
})
exportclassFeatureAServiceimplementsMQable{
constructor(){}
connect(mq:RxmqService){
console.log('FeatureAService.connect',mq);
mq.channel('demo-a').observe('add.element')
.subscribe((event)=>{
console.log('Feature A service: demo-a:add.element',event);