定制 landingi/modular-monolith-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

landingi/modular-monolith-bundle

Composer 安装命令:

composer require landingi/modular-monolith-bundle

包简介

Landingi Modular Monolith bundle

README 文档

README

Build Status License MIT Packagist Version

Modules in Modular Monolith

From the point of view of a modular monolith, it is important not to introduce code level coupling between its modules.

Communication

Communication within a modular monolith between specific modules should not introduce code level couplings. Each module must be treated as a separate element of the system (we can even say that each module is a microservice inside the monolith). In order to meet such requirements, communication between modules can be carried out in two ways, depending on the specific demand.

The way of communication is modeled on that presented by Bottega (Devmentors) in their example Modular Monolith written in .net technology. The idea was absorbed and adapted to PHP technology (unfortunately, not everything could be done as nicely and generically as in .net).

  • (NOT READY) We can react to public events (application / integration) from the point of view of the module.
  • (READY) We can throw requests to a specific module using a mechanism similar to the Http protocol. This implementation is now ready and usable. The whole thing works completely inside the memory which guarantees high performance.

In the event-driven architecture, communication mainly takes place through integration events. However, not everything is playable by events. These are mainly modules containing generic contexts that can be used by multiple modules. Here, "module requests" comes to our aid.

1. Integration/application events

(To be implemented)

2. Module requests

The idea behind requests between modules using what we have termed "module request" is to be able to communicate between modules within a modular monolith as if we had a distributed architecture in the case of microservices. This allows us to run the project without introducing hacks and couplings between specific elements of the system. In addition, the implementation allows you to easily extract a specific module as a microservice, if necessary.

Of course, the current implementation is just the beginning. It supports the basic assumptions, but there is probably room for improvement. The current implementation is inside the memory, if one day one of the modules is pulled out as a microservice beyond a monolith, then a new ModuleClient implementation should be added to support communication via the infrastructure.

2. 1. How it works?

Any module wishing to make a certain resource available for other modules should add "request handler" at a specific path (the path should be in a format similar to that of HTTP, for example: "module/acl/v1/is-functionality-granted". Subscribing at this time all requests going to this path in the same way as we would do in the case of API via HTTP, except that everything happens by default in memory (of course, extracting the module as a microservice and changing communication is not a problem as I mentioned before).

So we are registering the handler in Symfony DI using tag: app.module.handler with given request path: module/acl/v1/is-functionality-granted:

Acl\Application\ModuleRequest\Handler\IsFunctionalityGrantedHandler:
    arguments: ['@Acl\Application\Service\AccessService']
    tags:
        - { name: 'app.module.handler', path: 'module/acl/v1/is-functionality-granted' }

This handler will handle requests to ACL to check permissions from the other modules, and again exactly in the same way as it would be in HTTP API.

Then, from the level of another module, e.g. lightboxes, we can easily introduce the ACL checking service (remember that each module is an individual entity). In this service we will simply call via ModuleClient our created handler without any code level coupling:

use SharedKernel\Application\Module\GenericMessage;

$accountUuid = 'c87ceb7b-4272-4126-abeb-1d778ff89ed2';
$userUuid = '639e4f08-d176-4c15-9f2f-94ad69d6ccd9';
$functionalityPermission = 'lightboxes.view_list';

$result = $this->moduleClient->request(
    'module/acl/v1/is-functionality-granted',
    new GenericMessage(
        [
            'account_uuid' => (string) $accountUuid,
            'user_uuid' => (string) $userUuid,
            'permission' => $functionalityPermission
        ]
    )
);

In the $result variable we will simply get our handler result. Exactly the same way as we would while calling the HTTP API.

landingi/modular-monolith-bundle 适用场景与选型建议

landingi/modular-monolith-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 landingi/modular-monolith-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 landingi/modular-monolith-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 landingi/modular-monolith-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-18