How apache/dubbo-erlang works
Project Type and Purpose
• dubboerl is a library/framework (not a user-facing app) that implements the Dubbo RPC protocol in Erlang.
• It provides:
• Core Erlang modules for protocol handling, registry, cluster, load-balancing, serialization (Hessian/JSON), connection pooling, filters, etc.
• A Java-based “erlanalysis” tool to generate Erlang bindings from Java interfaces.
• Sample consumer/provider apps in Java and Erlang.
File Structure
• Top-level directories:
• src/ (Erlang implementation modules)
• / (shared .hrl headers defining record types and macros)
• test/ (EUnit suites covering each core module)
• tools/erlanalysis (Java Maven project that parses Java interfaces and outputs Erlang code)
• samples/ (demo Java service, Erlang demo app)
• config_example, docs, rebar.config, README.md
Key Architectural Insights from the README
• dubboerl runs under Erlang/OTP, managed by a supervision tree (dubboerl_sup).
• It connects to a Zookeeper registry for service discovery.
• It speaks the Dubbo binary protocol over TCP, serializes payloads via Hessian or JSON.
• It uses extension points (behaviours) for protocol, cluster, registry, filters, load-balance.
Main Components
a. Erlanalysi s Tool (Java)
• Input: Java interfaces & JARs
• Output: Erlang module templates and .hrl files
• Relationship: Generates code that lives under your project’s app/src
b. Erlang Application (dubboerl OTP App)
• Supervision Tree: dubboerl_sup → children processes
• Core Modules (grouped by function):
• Configuration & Init: dubbo_config_util, dubboerl:init
• Registry & Discovery: dubbo_registry, dubbo_registry_zookeeper
• Protocol & Codec: dubbo_protocol, dubbo_codec, cotton_hessian
• Cluster & Load-Balance: dubbo_cluster, dubbo_loadbalance_random
• Consumer/Invoker: dubbo_reference_config, dubbo_invoker
• Provider/Worker: dubbo_provider_protocol, dubbo_provider_worker
• Connection Pool & Transport: dubbo_transport_pool_sup
• Extension & Filter Points: dubbo_extension, dubbo_filter
• Data Flow:
Erlang consumer call → invoker → transport pool → remote node → Hessian/JSON codec → provider → business code → reverse flow
c. External Systems
• Zookeeper Cluster (Registry Center)
• Java Dubbo Providers/Consumers (optional peers)
d. Sample Apps
• Java sample service (Spring/Maven) registers via ZK
• Erlang demo app (samples/dubboerl_demo) as consumer & provider, using generated code
Relationships & Interactions
• The erlanalysis tool → generates Erlang interface libs → included in the Erlang demo app
• At runtime, dubboerl:init() → starts OTP app → reads sys.config → spins up registry client → registers provider or subscribes consumer
• Consumer process → sends RPC request via TCP over Dubbo protocol → uses serialization → remote provider node → invokes implementation → returns response
• Registry client maintains subscriptions/registrations in ZK, handles node changes
Architectural Patterns & Principles
• OTP Supervision Tree (fault-tolerance)
• Behaviour-based extensions for protocol, registry, cluster, filters
• Process per connection / worker pool
• Separation of concerns: config, registry, protocol, serialization, transport, business code
Technologies & Frameworks
• Erlang/OTP (rebar3)
• Zookeeper (via dubbo_registry_zookeeper)
• Java/Maven for erlanalysis tool
• Hessian and JSON codecs