This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ceb-messaging-moleculer): add an implementation which leverage o…
…n Moleculer
- Loading branch information
Showing
29 changed files
with
1,985 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Implementations | ||
|
||
## The reference implementation | ||
|
||
> The reference implementation is defined in the NPM package [@tmorin/ceb-messaging-simple](https://www.npmjs.com/package/@tmorin/ceb-messaging-simple). | ||
The reference implementation relies on an in-memory and single process approach. | ||
So that, the implementation is free of network or any other concerns related to distributed systems. | ||
|
||
### The SimpleGateway | ||
|
||
A SimpleGateway instance can be got from the following three approaches: the global instance, the factory method or the constructor. | ||
|
||
#### The global instance | ||
|
||
A global instance of the SimpleGateway is available from the static field `SimpleGateway.GOBAL`. | ||
It's a lazy property, in fact the instance is only created once at its first get. | ||
|
||
```typescript | ||
{{#include ../../packages/ceb-book-samples/src/messaging/implementation-create_global.ts}} | ||
``` | ||
|
||
#### The factory method | ||
|
||
A SimpleGateway instance can be easily created using the factory method, i.e. the static method `SimpleGateway.create()`. | ||
The method returns a fresh new SimpleGateway instance at each call. | ||
|
||
```typescript | ||
{{#include ../../packages/ceb-book-samples/src/messaging/implementation-create_factory.ts}} | ||
``` | ||
|
||
#### The constructor | ||
|
||
The constructor approach provides a fine grain control of the Gateway dependencies: the CommandBus, the QueryBus, the EventBus and the GatewayObserver. | ||
|
||
```typescript | ||
{{#include ../../packages/ceb-book-samples/src/messaging/implementation-create_constructor.ts}} | ||
``` | ||
|
||
### The Inversion Module | ||
|
||
The package provides an Inversion Module which can be used to create (optionally) and publish the SimpleGateway instance on the registry. | ||
|
||
Create a container with the default module behavior, i.e. the SimpleGateway will be created from scratch automatically: | ||
```typescript | ||
{{#include ../../packages/ceb-book-samples/src/messaging/implementation-inversion-default.ts}} | ||
``` | ||
|
||
Create a container with a provided SimpleGateway instance: | ||
```typescript | ||
{{#include ../../packages/ceb-book-samples/src/messaging/implementation-inversion-global.ts}} | ||
``` | ||
|
||
## The Moleculer implementation | ||
|
||
> The Moleculer implementation is defined in the NPM package [@tmorin/ceb-messaging-moleculer](https://www.npmjs.com/package/@tmorin/ceb-messaging-moleculer). | ||
The [Moleculer] implementation leverages on the features provided by the microservices framework. | ||
|
||
## Management of Commands and Queries | ||
|
||
There is one [Moleculer service] per command or query types. | ||
For instance, the command type `CommandA` will be managed by the service `CommandA`. | ||
|
||
About commands, each service provides two [Moleculer actions]: `execute` and `executeAndForget`. | ||
The first one executes the command handler and return the result. | ||
The second one just executes the command handler at the next clock thick. | ||
For instance, the command type `CommandA` can be executed within the Moleculer world with the actions `CommandA.execute` and `CommandA.executeAndForget`. | ||
Each action accepts only one parameter: the command. | ||
|
||
About queries, each service provides only one action: `execute`. | ||
The action executes the query handler and return the result. | ||
For instance, the query type `QueryA` can be executed within the Moleculer world with the action `QueryA.execute`. | ||
The action accepts only one parameter: the query. | ||
|
||
## Management of Events | ||
|
||
The Events are managed by a single [Moleculer service]: `EventBus`. | ||
Each time an Event is published, the type of [Moleculer event] is `Event.MESSAGE_TYPE`. | ||
For instance, when the Event `EventA` is published, the Moleculer event name is `EventBus.EventA`. | ||
|
||
By default, the implementation publish messaging using the _balanced_ mode. | ||
Because of the single Moleculer service `EventBus`, it means each Event will only be handled by only one service in the cluster. | ||
|
||
|
||
[Moleculer]: https://moleculer.services | ||
[Moleculer service]: https://moleculer.services/docs/0.14/actions.html | ||
[Moleculer actions]: https://moleculer.services/docs/0.14/actions.html | ||
[Moleculer event]: https://moleculer.services/docs/0.14/events.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# @tmorin/ceb-messaging-moleculer | ||
|
||
[![npm version](https://badge.fury.io/js/%40tmorin%2Fceb-messaging-moleculer.svg)](https://badge.fury.io/js/%40tmorin%2Fceb-messaging-moleculer) | ||
[![skypack.dev](https://img.shields.io/badge/-skypack.dev-blueviolet.svg)](https://www.skypack.dev/view/@tmorin/ceb-messaging-moleculer) | ||
[![doc](https://img.shields.io/badge/-doc-informational.svg)](https://tmorin.github.io/ceb) | ||
[![api](https://img.shields.io/badge/-api-informational.svg)](https://tmorin.github.io/ceb/api/modules/_tmorin_ceb_messaging_moleculer.html) | ||
|
||
> The package is part of the `<ceb/>` library. | ||
> It provides an implementation of the messaging model leveraging on Moleculer. | ||
## Install | ||
|
||
The NPM package is compliant [CommonJs](https://flaviocopes.com/commonjs) and [ES Module](https://flaviocopes.com/es-modules). | ||
|
||
```bash | ||
npm install @tmorin/ceb-messaging-moleculer | ||
``` | ||
|
||
## License | ||
|
||
Released under the [MIT license]. | ||
|
||
[Custom Elements (v1)]: https://html.spec.whatwg.org/multipage/custom-elements.html | ||
[MIT license]: http://opensource.org/licenses/MIT |
Oops, something went wrong.