msgpack serialization

Using msgpack serialization in Dubbo

MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it’s faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

msgpack demo

    1. provider and consumer import msgpack dependencies

    1. provider demo

Add the following protocol configurations into Dubbo configuration class:

	public ProtocolConfig msgpackProtocol(){
        ProtocolConfig protocolConfig = new ProtocolConfig();
        return protocolConfig;

Dubbo provider:

Add protocol declaration protocol = {“msgpackProtocol”} to annotations of @Service implemented by Dubbo provider interface.

Dubbo provider interface:

public interface MsgpackService {
    int tint(int i);
    long tlong(long i);
    List<String> tlist(List<String> l);
    String multiParams(String str, int i, MyParam myParam);

Dubbo provider interface implement:

@Service(interfaceClass = MsgpackService.class,protocol = {"msgpackProtocol"})
public class MsgpackServiceImpl implements MsgpackService {
    public int tint(int i) {
        return i;
    public long tlong(long i) {
        return i;
    public List<String> tlist(List<String> l) {
        return l;
    public String multiParams(String str, int i, MyParam myParam) {
        return str + i + myParam.getName() + myParam.getAge();

Entities used:

public class MyParam {
    private String name;
    private int age;
    public MyParam(String name, int age) { = name;
        this.age = age;
    // parameterless construct function needed
    public MyParam(){}
    1. consumer demo
    @DubboReference(interfaceClass = MsgpackService.class)
    private MsgpackService msgPackService;
    public String testMsgpack(){
        int v1 = msgPackService.tint(1);
        long v2 = msgPackService.tlong(2);
        List<String> v3 = msgPackService.tlist(Lists.newArrayList("1","2","3"));
        String v4 = msgPackService.multiParams("hello", 3, new MyParam("Tom", 24));
        return "msgpack"+v1+" "+v2+" "+v3+" "+v4;
    1. invoke
> curl http://localhost:8081/msgpack
> msgpack1 2 [1, 2, 3] hello3Tom24