### Extended RpcMeta Protocol Definition (Hulu Example)
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/RPC通讯协议规范
An example of extending RpcMeta with proprietary fields, using an assigned sequence number (100 for Hulu) to avoid conflicts.
```protobuf
message RpcMeta {
optional RpcRequestMeta request = 1;
optional RpcResponseMeta response = 2;
optional int32 compress_type = 3;
optional int64 correlation_id = 4;
optional int32 attachment_size = 5;
optional ChunkInfo chuck_info = 6;
};
message RpcRequestMeta {
required string service_name = 1;
required string method_name = 2;
optional int64 log_id = 3;
};
message RpcResponseMeta {
optional int32 error_code = 1;
optional string error_text = 2;
};
```
--------------------------------
### Expose RPC Service using RpcServiceExporter (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/User-Guide
Configure RpcServiceExporter in Spring XML to expose an RPC service. This example exposes an EchoServiceImpl instance.
```xml
```
--------------------------------
### Common Annotation Bean Post Processor Configuration
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Configures the CommonAnnotationBeanPostProcessor for handling RPC annotations in Spring. This setup is often simplified or handled automatically in Spring Boot.
```xml
```
--------------------------------
### Component Scan and Annotation Bean Post Processor Configuration
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Recommended configuration for annotation-based RPC, including component scanning and the CommonAnnotationBeanPostProcessor.
```xml
```
--------------------------------
### Expose RPC Service with EchoServiceImpl
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Defines an EchoServiceImpl class with a method annotated with @ProtobufRPCService to be exposed as an RPC service.
```java
public class EchoServiceImpl {
@ProtobufRPCService(serviceName = "echoService", methodName = "echo")
public EchoInfo doEcho(EchoInfo info) {
EchoInfo ret = new EchoInfo();
ret.setMessage("hello:" + info.getMessage());
return ret;
}
}
```
--------------------------------
### Configure NamingService for HaRpcProxy (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/User-Guide
XML configuration for NamingService, which is required by @HaRpcProxy to provide a list of server addresses for load balancing.
```xml
localhost:1031;localhost:1032;localhost:1033
```
--------------------------------
### Client Connection using RpcProxyFactoryBean (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Configures RpcProxyFactoryBean in Spring XML to create a proxy for the EchoService, connecting to the RPC server on port 1031.
```xml
```
--------------------------------
### Client Connection using RpcProxyFactoryBean (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/User-Guide
Configure RpcProxyFactoryBean in Spring XML to create a client proxy for an RPC service. This connects to the EchoService.
```xml
```
--------------------------------
### Configure Annotation Bean Post Processor
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/User-Guide
This common configuration is required for both publishing and consuming services using annotations. It sets up the annotation resolver.
```xml
```
--------------------------------
### Client Connection using @RpcProxy Annotation
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Declares an EchoService client using the @RpcProxy annotation, specifying connection details and the service interface.
```java
@Service("echoServiceClient")
public class AnnotationEchoServiceClient {
@RpcProxy(port = "1031", host = "127.0.0.1", serviceInterface = EchoService.class, lookupStubOnStartup = false)
public EchoService echoService;
}
public interface EchoService {
@ProtobufRPC(serviceName = "echoService", onceTalkTimeout = 1000)
EchoInfo echo(EchoInfo info);
}
```
--------------------------------
### Load Balancing Client Connection using HaRpcProxyFactoryBean (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Configures HaRpcProxyFactoryBean for load-balanced client connections, using a NamingService to provide a list of service endpoints.
```xml
localhost:1031;localhost:1032;localhost:1033
```
--------------------------------
### Expose RPC Service using @RpcExporter Annotation
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Exposes an EchoServiceImpl as an RPC service using the @RpcExporter annotation, specifying the port.
```java
@Component
@RpcExporter(port = "1031")
public class EchoServiceImpl {
@ProtobufRPCService(serviceName = "echoService", methodName = "echo")
public EchoInfo doEcho(EchoInfo info) {
EchoInfo ret = new EchoInfo();
ret.setMessage("hello:" + info.getMessage());
return ret;
}
}
```
--------------------------------
### Define EchoService Interface for Client
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Defines the EchoService interface with the @ProtobufRPC annotation, mirroring the exposed RPC service for client-side usage.
```java
public interface EchoService {
@ProtobufRPC(serviceName = "echoService", onceTalkTimeout = 1000)
EchoInfo echo(EchoInfo info);
}
```
--------------------------------
### RpcRequestMeta Protocol Definition
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/RPC通讯协议规范
Specifies the metadata for an RPC request, including the service name, method name, and an optional log ID.
```protobuf
message RpcRequestMeta {
required string service_name = 1;
required string method_name = 2;
optional int64 log_id = 3;
};
```
--------------------------------
### Expose RPC Service using RpcServiceExporter (XML)
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Configures RpcServiceExporter in Spring XML to expose an EchoServiceImpl instance as an RPC service on port 1031.
```xml
```
--------------------------------
### RpcMeta Protocol Definition
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/RPC通讯协议规范
Defines the metadata structure for RPC requests and responses, including optional fields for request/response details, compression, correlation ID, and attachments.
```protobuf
message RpcMeta {
optional RpcRequestMeta request = 1;
optional RpcResponseMeta response = 2;
optional int32 compress_type = 3;
optional int64 correlation_id = 4;
optional int32 attachment_size = 5;
optional ChunkInfo chuck_info = 6;
optional bytes authentication_data = 7;
};
```
--------------------------------
### Load Balancing Client Connection using @HaRpcProxy Annotation
Source: https://github.com/baidu/jprotobuf-rpc-socket/blob/master/user_guide.md
Configures a load-balanced client connection using @HaRpcProxy, referencing a NamingService bean defined in XML.
```java
@Service("echoServiceClient")
public class AnnotationEchoServiceClient {
@HaRpcProxy(namingServiceBeanName = "namingService", serviceInterface = EchoService.class,
lookupStubOnStartup = false)
public EchoService haEchoService;
}
public interface EchoService {
@ProtobufRPC(serviceName = "echoService", onceTalkTimeout = 1000)
EchoInfo echo(EchoInfo info);
}
```
--------------------------------
### RpcResponseMeta Protocol Definition
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/RPC通讯协议规范
Defines the metadata for an RPC response, including optional error code and error text for reporting issues.
```protobuf
message RpcResponseMeta {
optional int32 error_code = 1;
optional string error_text = 2;
};
```
--------------------------------
### ChunkInfo Protocol Definition
Source: https://github.com/baidu/jprotobuf-rpc-socket/wiki/RPC通讯协议规范
Defines the structure for chunk information, used in chunk mode to identify data streams and individual chunks.
```protobuf
messsage ChunkInfo {
required int64 stream_id = 1;
required int64 chunk_id = 2;
};
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.