SOFARPC Documentation
repository·master·Indexed 26 days ago
https://github.com/sofastack/sofa-rpcA production-grade Java RPC framework designed for high-performance, extensible, and stable point-to-point remote service invocation in microservices architectures. It supports multiple protocols (Bolt, Rest, Dubbo), various invocation modes (synchronous, one-way, callback, generalized), and integrates with service registries. The framework provides features for routing, load balancing, cluster fault tolerance, and service warming, requiring JDK 8 and Maven 3.2.5 or above for build and runtime.
What's inside SOFARPC
- SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework designed to simplify remote service invocation between applications. It provides stable, efficient point-to-point communication with minimal code intrusion. The framework is highly extensible through model abstractions and interfaces for filters, routing, load balancing, and more. It also supports a rich MicroService governance ecosystem.
Design overview of SOFA-RPC HTTP protocol
masterThe SOFA-RPC HTTP protocol supports both HTTP/1.1 and HTTP/2 designs.
- HTTP/1.1: Provides server-side support only.
- HTTP/2: Supports both server and client, but does not currently support streaming calls.
Default Settings:
- Server Port:
12300(default) - Keep-Alive:
true(default for both server and client)
Key Features of SOFARPC
masterSOFARPC supports the following capabilities:
- Transparent & High-Performance Calls: Simplified remote service invocation.
- Routing & Load Balancing: Supports multiple service routing and load balancing strategies.
- Registry Integration: Supports integration with various service registries.
- Multiple Protocols: Supports Bolt, Rest, Dubbo, and other protocols.
- Diverse Invocation Modes: Supports synchronous, one-way, callback, and generalized (泛化) calling methods.
- Fault Tolerance & Stability: Supports cluster fault tolerance, service warming, and automatic fault isolation.
- Extensibility: Powerful extension mechanism to add functional components on demand.
Construct URL and URI for HTTP calls
masterThe URL/URI follows this format:
${protocol}://${ip}:${port}/${interfaceName}[:${uniqueId}]/methodName- Recommended Method: Use
POSTfor standard calls. - Simple Functions: Can use
GETwith query parameters.
Examples:
POST (Standard):
POST h2c://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService/sayHelloGET (Simple):
GET http://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService:1.0:groupA/sayHello?name=zhang&age=123POST h2c://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService/sayHello GET http://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService:1.0:groupA/sayHello?name=zhang&age=123- Recommended Method: Use
Handle HTTP Responses and Errors
masterResponses are categorized into three states:
1. Successful Response
- HTTP Status Code:
200 - Headers:
sofa_head_serialize_type(Required) andcontent-type(Required, defaults toapplication/json). - Body: The serialized return value (e.g., a JSON string:
"Hello world").
2. Business Exception (Application Error)
- HTTP Status Code:
200 - Headers:
sofa_head_resp_erroris set totrue. - Body: A UTF-8 encoded error description string (e.g.,
java.lang.RuntimeException: 业务异常).
3. RPC Framework Exception
- HTTP Status Code: Not
200(e.g.,404for service not found,400for bad requests). - Body: A UTF-8 encoded error description string (e.g.,
RPC-02411: 未找到业务服务...).
- HTTP Status Code:
System requirements for SOFARPC
masterTo use or build SOFARPC, ensure your environment meets the following requirements:
Build-time requirements:
- JDK 8 or above
- Maven 3.2.5 or above
Runtime requirements:
- JDK 8 or above
SOFARPC Documentation and Guides
masterAccess the following resources for detailed information:
- Quick Start: Getting Started with SOFA Boot
- User Manual: Programming Guide
- Developer Guide: How to Build
- Release History: Release Notes
- Roadmap: Development Roadmap
Requirements for SOFARPC
masterTo use or build SOFARPC, ensure your environment meets the following requirements:
For Compilation:
- JDK 8 or higher
- Maven 3.2.5 or higher
For Runtime:
- JDK 8 or higher
Access SOFARPC documentation and guides
masterDetailed documentation is available through the following resources:
- Getting Started: Getting Started with SOFA-Boot
- User Guide: Programming Guide
- Developer Guide: How to Build
- Release Notes: Version History
- Road Map: Project Roadmap
Reference Response Headers
masterThe following headers are used in the HTTP response:
HEAD Meaning Required Notes sofa_head_serialize_typeSerialization type Yes If not set, content-typeis usedcontent-typeSerialization Yes Defaults to application/jsonsofa_head_resp_errorIndicates if the response is an exception No sofa_head_resp_baggageResponse baggage (pass-through) No | HEAD | 含义 | 必填 | 备注 | |:-------------------------|:----------|:----|:-----------------------------------| | sofa_head_serialize_type | 序列化类型 | 是 | 如果没有设置这个值将读取 content-type | | content-type | 序列化 | 是 | 默认 application/json | | sofa_head_resp_error | 返回是否异常 | 否 | | | sofa_head_resp_baggage | 响应透传值 | 否 | |Format the Request Body for HTTP calls
masterThe Request Body must contain the serialized parameter values.
Example (JSON serialization of an
Object[]):["zhang", 123]["zhang", 123]Configure Request Headers for HTTP calls
masterWhen making an RPC call via HTTP, use the following headers to control serialization and metadata:
HEAD Meaning Required Notes sofa_head_serialize_typeSerialization type Yes If not set, content-typeis usedcontent-typeSerialization No sofa_head_target_appTarget application No sofa_head_req_propsRequest additional properties No sofa_head_req_baggageRequest baggage (pass-through) No Supported
content-typevalues:hessian2:x-application/hessianjson:application/jsonprotobuf:application/x-protobuf
| HEAD | 含义 | 必填 | 备注 | |:-------------------------|:----------|:----|:-----------------------------------| | sofa_head_serialize_type | 序列化类型 | 是 | 如果没有设置这个值将读取 content-type | | content-type | 序列化 | 否 | | | sofa_head_target_app | 目标应用 | 否 | | | sofa_head_req_props | 请求附加值 | 否 | | | sofa_head_req_baggage | 请求透传值 | 否 | |