Messaging client for inter-service communication via the message broker service.
Here is an example of how you can use the messenger in a Nest.js provider
import { Injectable, OnModuleDestroy } from '@nestjs/common';
import { Messenger } from 'messenger';
import { Subscription } from 'rxjs';
@Injectable()
class ExampleProvider implements OnModuleDestroy {
messenger: Messenger;
msgConnectSub: Subscription;
msgMessageSub: Subscription;
constructor() {
this.messenger = Messenger.getInstance(ServiceConfig.name);
this.msgConnectSub = this.messenger.onConnectionChange.subscribe((state) =>
this.handleConnectStateChange(state)
);
}
onModuleDestroy() {
this.msgConnectSub.unsubscribe();
this.msgMessageSub.unsubscribe();
}
handleConnectStateChange(state) {
if (state === Messenger.CONNECTED) {
this.msgMessageSub = this.messenger.subscribe('new-aggregator-config');
this.msgMessageSub.on('message', (message) =>
this.handleMessage(message)
);
}
}
handleMessage(message) {
console.log(message);
}
}Prerequesits:
Install in your project:
Run:
$ npm i -S git+https://git@github.com/IRT-Open-Source/5gv-messenger.gitBuild:
Note: This library is used by services which are build and run by the up.sh script of the Platform project. Typically you would only need to run the following commands, if you need to make changes to this project.
Clone this repository, change into its root directory and run following command to install its dependencies:
$ npm iBuild JavaScript modules from typescript source:
$ npx tscCurrently, the scripts in directory /dist are built from the sources using the typscript compiler tsc and checked into the git repository. This is considered to be a bad style. For one it creates unnecessary overhead (memory + files to track). Much more important, it is not obvious if the files in /dist correspond to the current development status of the sources -- no single source of truth. Actually, the files in /dist should be built after the installation via NPM at the user's site, for example by a postinstall script defined in the package.json. However, this approach could not be implemented successfully so far. In consuming services, errors were encountered during build of the docker images when NPM attempted to resolve the dependencies or to build the scripts.

