All Products
Search
Document Center

Serialization Protocols

Last Updated: Aug 17, 2020

SOFARPC can use different serialization protocols under the Bolt protocol. Currently, it can use hessian2 and protobuf. SOFARPC uses hessian2 by default.

Currently, you cannot set the serialization protocol through annotation. This will be supported in later versions.

The XML configurations are as follows:

Publish a service

If you need to set the serialization protocol to protobuf when publishing a service., you need to add <sofa:global-attrs> to the <sofa:binding.bolt> tag, and set serialize-type to protobuf.

  1. <sofa:service ref="sampleService" interface="com.alipay.sofarpc.demo.SampleService">
  2. <sofa:binding.bolt>
  3. <sofa:global-attrs serialize-type="protobuf"/>
  4. </sofa:binding.bolt>
  5. </sofa:service>

Reference a service

Accordingly, you need to set the serialization protocol to protobuf when referencing a service. The configuration method is similar to that for publishing a service.

  1. <sofa:reference interface="com.alipay.sofarpc.demo.SampleService" id="sampleServiceRef" jvm-first="false">
  2. <sofa:binding.bolt>
  3. <sofa:global-attrs serialize-type="protobuf"/>
  4. </sofa:binding.bolt>
  5. </sofa:reference>