Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
feat(ceb-messaging-moleculer): add an implementation which leverage o…
Browse files Browse the repository at this point in the history
…n Moleculer
  • Loading branch information
tmorin committed Dec 23, 2021
1 parent 401530e commit 48eee90
Show file tree
Hide file tree
Showing 29 changed files with 1,985 additions and 64 deletions.
1 change: 1 addition & 0 deletions .idea/ceb.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Expand Up @@ -78,6 +78,7 @@ A built-in implementation of the Event/Message architecture:

- [ceb-messaging-core](./packages/ceb-messaging-core)
- [ceb-messaging-inversion](./packages/ceb-messaging-inversion)
- [ceb-messaging-moleculer](./packages/ceb-messaging-moleculer)
- [ceb-messaging-simple](./packages/ceb-messaging-simple)
- [ceb-messaging-simple-builder](./packages/ceb-messaging-simple-builder)
- [ceb-messaging-builder-core](./packages/ceb-messaging-builder-core)
Expand Down
1 change: 1 addition & 0 deletions README.typedoc.md
Expand Up @@ -37,6 +37,7 @@ A built-in implementation of the Event/Message architecture:

- [ceb-messaging-core](modules/_tmorin_ceb_messaging_core.html)
- [ceb-messaging-inversion](modules/_tmorin_ceb_messaging_inversion.html)
- [ceb-messaging-moleculer](modules/_tmorin_ceb_messaging_moleculer.html)
- [ceb-messaging-simple](modules/_tmorin_ceb_messaging_simple.html)
- [ceb-messaging-simple-builder](modules/_tmorin_ceb_messaging_simple_builder.html)
- [ceb-messaging-simple-inversion](modules/_tmorin_ceb_messaging_simple_inversion.html)
Expand Down
2 changes: 1 addition & 1 deletion book/SUMMARY.md
Expand Up @@ -11,7 +11,7 @@
- [Messages](messaging/messages.md)
- [Gateway](messaging/gateway.md)
- [Inversion integration](messaging/inversion.md)
- [Reference Implementation](messaging/implementation.md)
- [Implementations](messaging/implementations.md)
- [Adapters](messaging/adapters.md)
- [Elements](elements/README.md)
- [ElementBuilder](elements/ElementBuilder.md)
Expand Down
50 changes: 0 additions & 50 deletions book/messaging/implementation.md

This file was deleted.

89 changes: 89 additions & 0 deletions book/messaging/implementations.md
@@ -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
1 change: 1 addition & 0 deletions book/packages.md
Expand Up @@ -14,6 +14,7 @@ Inversion Of Control:
Event/Message Architecture:
- [@tmorin/ceb-messaging-core](https://www.npmjs.com/package/@tmorin/ceb-messaging-core)
- [@tmorin/ceb-messaging-inversion](https://www.npmjs.com/package/@tmorin/ceb-messaging-inversion)
- [@tmorin/ceb-messaging-moleculer](https://www.npmjs.com/package/@tmorin/ceb-messaging-moleculer)
- [@tmorin/ceb-messaging-simple](https://www.npmjs.com/package/@tmorin/ceb-messaging-simple)
- [@tmorin/ceb-messaging-simple-builder](https://www.npmjs.com/package/@tmorin/ceb-messaging-simple-builder)
- [@tmorin/ceb-messaging-testing](https://www.npmjs.com/package/@tmorin/ceb-messaging-testing)
Expand Down
1 change: 1 addition & 0 deletions lerna.json
Expand Up @@ -17,6 +17,7 @@
"packages/ceb-messaging-builder-inversion",
"packages/ceb-messaging-core",
"packages/ceb-messaging-inversion",
"packages/ceb-messaging-moleculer",
"packages/ceb-messaging-simple",
"packages/ceb-messaging-simple-builder",
"packages/ceb-messaging-simple-inversion",
Expand Down
3 changes: 2 additions & 1 deletion packages/ceb-messaging-adapter-purify/package.json
Expand Up @@ -15,7 +15,8 @@
"cqrs",
"bus",
"event-bus",
"message-bus"
"message-bus",
"purify"
],
"homepage": "https://tmorin.github.io/ceb",
"bugs": {
Expand Down
24 changes: 24 additions & 0 deletions packages/ceb-messaging-moleculer/README.md
@@ -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

0 comments on commit 48eee90

Please sign in to comment.