##定位

“Dubbo Producer refers to ‘service provider’, responsible for implementing business interfaces and exporting them to registry/config center through Dubbo framework, enabling consumers to invoke transparently.”

Role and Responsibilities

  • Interface Implementation: Expose Java implementation class of business interface as remote service
  • Protocol Exposure: Convert interface to remotely callable Protocol + Serialization
  • Registry Governance: Report to Registry, renew lease, go offline
  • Runtime Resources: Manage thread pool, connection pool, serialization buffer
  • Service Governance: Version, group, weight, rate limiting, circuit breaker

Key Components

Thread Pool

“Handle business method calls; default FixedThreadPool + Queue, custom ‘isolated thread pool’ for high-traffic interfaces to avoid blocking global operations”

Serialization (Serialization SPI)

“Object ↔ ByteBuf; default Hessian2, recommended to switch to Protobuf/FST/Kryo for 20-50% throughput improvement”

Connection Pool (ChannelPool)

“Long connection reuse, default lazyInit + heartbeat”

Filter (Filter SPI)

“Server-side chain interception: logging, authorization, rate limiting, grayscale”

POM

<dependency>
    <groupId>icu.wzk</groupId>
    <artifactId>wzk-service-api</artifactId>
</dependency>

Producer Definition

@Service
public class WzkHelloServiceImpl implements WzkHelloService {
    @Override
    public String sayHello(String name) {
        return "hello ? " + name;
    }
}

Configuration File

dubbo.application.name=dubbo-demo-annotation-provider
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880

Configuration Class

@Configuration
@EnableDubbo(scanBasePackages = "icu.wzk.service.impl")
@PropertySource("classpath:/dubbo-provider.properties")
public class ProviderConfiguration {
    @Bean
    public RegistryConfig registryConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress("zookeeper://10.10.52.38:2181");
        return registryConfig;
    }
}

Spring Boot Example

@DubboService(version = "1.0.0", timeout = 3000, retries = 0, executes = 200)
public class OrderServiceImpl implements OrderService {
    @Override
    public OrderSubmitResult submit(OrderDTO in) {
        // Business logic...
        return in;
    }
}

Startup Flow

  1. Spring Bootstrapping: DubboBootstrap triggers afterPropertiesSet() when Spring container refresh completes
  2. Assemble ServiceConfig: Parse @DubboService, complete default values
  3. Generate Invoker: Wrapper: Javassist wraps target implementation class into Invoker
  4. Protocol.export(): Create Exporter, start Server and bind port
  5. Registry.register(): Generate URL and write to ZooKeeper node
  6. MetadataReport: Record interface, method, parameter type and other information
  7. QOS & Metrics: Provide operations commands and monitoring

Production Environment

  • Port Planning: Isolate internal and external networks; prioritize using 20880/20890 range
  • JVM Parameters: -Xms -Xmx -Xmn -XX:+UseG1GC
  • Observability: Embed TraceId; integrate SkyWalking/Zipkin for链路接入
  • Configuration Center: Dubbo 3 recommends unified Nacos/Apollo
  • CI/CD: Grayscale -> Full rollout; explicitly execute graceful shutdown in rollback scripts
  • Security: Enable TLS + Token verification