Mobile Development 18 min read

Componentization and Modular Event Message Bus in Meituan Android Apps

Meituan transformed its monolithic cash‑register apps into a component‑based architecture using WMRouter as the routing foundation and built a strongly‑constrained modular‑event message bus—leveraging annotations, generated interfaces, and LiveData—to ensure type‑safe, module‑scoped communication, improve code reuse, reduce coupling, and simplify maintenance.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
Componentization and Modular Event Message Bus in Meituan Android Apps

This article presents Meituan's experience with Android componentization and the design of a strong‑constraint component message bus called modular‑event . It aims to help developers who are exploring component‑based architectures for Android applications.

Why componentize? Componentization improves code reuse and reduces coupling between modules, making the codebase easier to maintain and decreasing bug rates.

Pre‑componentization state: The two Meituan cash‑register apps (Meituan Retail Cashier and Meituan Light Cashier) had a monolithic structure where the Business module depended on Service and Platform modules, leading to heavy inter‑module coupling.

Open‑source solutions surveyed:

CC – progressive componentization framework.

DDComponentForAndroid – router + interface sinking.

ModularizationArchitecture – explicit RouterResponse handling.

ARouter – routing engine (not a full component solution).

Jumei Router – similar router‑plus‑interface approach.

Meituan internal solutions examined:

ComponentCenter – supports both interface calls and message‑bus communication.

App ServiceLoader – annotation‑based interface loading.

WMRouter – Meituan Waimai's Android routing framework, providing clear architecture and extensibility.

After evaluation, WMRouter was chosen as the base infrastructure. However, WMRouter lacks a message‑bus component, so the team built modular‑event to fill this gap.

Design goals of modular‑event:

Messages are defined by the component that owns them.

Same‑named messages from different components are distinguished.

Constraints prevent ad‑hoc message creation and enforce type safety.

Implementation highlights:

Two‑level HashMap (module name → event name → LiveData) for storage.

Annotations @ModuleEvents and @EventType mark message definition classes.

An annotation processor generates an interface for each message class (e.g., EventsDefineOfDemoEvents).

Dynamic proxy implements the generated interfaces, routing calls to the appropriate LiveData instance.

Usage example (subscription):

ModularEventBus.get()
    .of(EventsDefineOfModuleBEvents.class)
    .EVENT1()
    .observe(this, new Observer<TestEventBean>() {
        @Override
        public void onChanged(@Nullable TestEventBean testEventBean) {
            Toast.makeText(MainActivity.this, "MainActivity received: " + testEventBean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    });

Usage example (publishing):

ModularEventBus.get()
    .of(EventsDefineOfModuleBEvents.class)
    .EVENT1()
    .setValue(new TestEventBean("aa"));

The framework supports various observation modes (lifecycle‑aware observe, sticky observeSticky, and forever variants) and posting methods ( setValue on the main thread, postValue from background threads).

Conclusion and future work: The article summarizes the componentization practice, the modular‑event design, and outlines future directions such as component version management, reuse across projects, CI integration, and scaffolding support.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

AndroidComponentizationMessage BusLiveDataModular EventWMRouter
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

0 followers
Reader feedback

How this landed with the community

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.