Backend Development 8 min read

Flow Engine and Plugin Extension Engine for Business Isolation and Extensibility in MemberClub

The article explains how the MemberClub open‑source project leverages a flow engine and plugin extension engine to achieve business code isolation and extensibility, illustrating the problems of if‑else branching in multi‑business systems, providing configuration examples, execution principles, and Java code snippets.

Architect
Architect
Architect
Flow Engine and Plugin Extension Engine for Business Isolation and Extensibility in MemberClub

As a programmer, the author emphasizes keeping code simple and avoiding over‑design, yet discovers that in a middle‑platform scenario, process orchestration becomes essential for maintaining business isolation and extensibility.

Without a flow engine, adding new business lines quickly leads to tangled if‑else logic, making maintenance error‑prone and testing unrealistic.

The solution presented is to use a flow engine and a plugin extension engine, allowing each business to configure its own execution chain and implement differential logic via extensions.

In the MemberClub project, the flow engine is used to configure different process chains for various membership purchase scenarios. The configuration class DemoMemberPurchaseExtension defines three execution chains.

Each flow node implements four methods: process , success , rollback , and callback . The execution order follows a responsibility‑chain pattern, invoking process sequentially, rolling back on exceptions, and finally calling success or callback as appropriate.

public
void execute(FlowChain
chain, T context) {
    Exception exception = null;
    int index = -1;
    for (FlowNode
node : chain.getNodes()) {
        try {
            node.process(context);
            index++;
        } catch (Exception e) {
            if (e instanceof SkipException) {
                CommonLog.warn("当前流程:{} 发出 Skip请求,后续流程不再执行", node.getClass().getSimpleName());
                break;
            }
            exception = e;
            break;
        }
    }
    if (exception != null) {
        for (int i = index; i >= 0; i--) {
            FlowNode
node = chain.getNodes().get(i);
            try {
                node.rollback(context, exception);
            } catch (Exception e) {
                CommonLog.error("rollback执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
            }
        }
    } else {
        for (int i = index; i >= 0; i--) {
            FlowNode
node = chain.getNodes().get(i);
            try {
                node.success(context);
            } catch (Exception e) {
                CommonLog.error("success 执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
            }
        }
    }
    for (int i = index; i >= 0; i--) {
        FlowNode
node = chain.getNodes().get(i);
        try {
            node.callback(context, exception);
        } catch (Exception e) {
            CommonLog.error("callback执行异常,忽略 name:{}", node.getClass().getSimpleName(), e);
        }
    }
    if (exception != null) {
        throw exception;
    }
}

The article also lists the open‑source repositories (Gitee and GitHub) and highlights the many technologies integrated in MemberClub, such as MyBatis‑Plus, ShardingSphere, Redis, Apollo, Spring Cloud, RabbitMQ, H2, Swagger, Lombok, and MapStruct, as well as the underlying components like the flow engine, extension engine, distributed retry, logging, inventory, distributed lock, Redis Lua, and Spring context utilities.

Readers are encouraged to explore the code, use the project as a learning reference for building business‑centric middle‑platform systems, and follow the author for more technical sharing.

Javaflow enginePlugin ArchitectureSpringBootbusiness isolation
Architect
Written by

Architect

Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.