All Projects → apache → Dubbo Go Hessian2

apache / Dubbo Go Hessian2

Licence: other
caucho hessian2 implementation in Go for [apache/dubbo-go](https://github.com/apache/dubbo-go) which is compatible with [dubbo-hessian-lite](https://github.com/apache/dubbo-hessian-lite)

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Dubbo Go Hessian2

Dubbogo
a golang micro-service framework compatible with alibaba dubbo
Stars: ✭ 258 (+76.71%)
Mutual labels:  dubbo, hessian
Raincat
强一致分布式事务框架
Stars: ✭ 1,785 (+1122.6%)
Mutual labels:  dubbo
Bytetcc Sample
Stars: ✭ 119 (-18.49%)
Mutual labels:  dubbo
Nutzwk
WK系列开发框架-V1至V5 Java开源企业级开发框架(单应用/微服务/分布式)
Stars: ✭ 1,629 (+1015.75%)
Mutual labels:  dubbo
Pepper Metrics
pepper metrics is a tool, it can helps you collect runtime performance use RED method, and then output as log / timeseries data, by default it use prometheus as datasource, grafana as UI
Stars: ✭ 119 (-18.49%)
Mutual labels:  dubbo
Xc Spring Cloud Alibaba
spring cloud alibaba(2.2.1最新版)+nacos+dubbo+gateWay+sentinel+rocketmq+(pgsql/mysql8.0的json支持)+ignite集成可用于docker分布式框架+分布式自动化任务+mybatis多数据源+seate+ shardingSphere分布式分库事务解决方案
Stars: ✭ 131 (-10.27%)
Mutual labels:  dubbo
Zeusspring
基于Spring Boot 2.0的前后端分离的快速开发平台,此仓库是后台部分; 前台:Vue+Element 后台:Spring Boot 2.0/Spring Security/JWT/Spring Data JPA+Mybatis-Plus/Redis/分布式限流/同步锁/验证码/动态权限管理 数据权限 工作流 代码生成 日志记录 第三方社交账号、短信登录
Stars: ✭ 117 (-19.86%)
Mutual labels:  dubbo
Alibabacloud Microservice Demo
An Alibaba Cloud native microservice demo powered by Apache Dubbo and Spring Cloud Alibaba
Stars: ✭ 145 (-0.68%)
Mutual labels:  dubbo
Skill6 Website Backend
java进阶开发,高级版web项目。基于dubbo实现分布式微服务架构,基于spring boot、spring mvc、mybatis、docker、ELK、redis、vue.js、node.js等技术实现的技术分享交流网站。网站名称:技术流,英文名:skill6。主要功能有:登录注册、单点登录、restful设计、文章及评论、代码及资源下载、主题讨论等。持续更新中...
Stars: ✭ 140 (-4.11%)
Mutual labels:  dubbo
Spring Boot Quick
🌿 基于springboot的快速学习示例,整合自己遇到的开源框架,如:rabbitmq(延迟队列)、Kafka、jpa、redies、oauth2、swagger、jsp、docker、spring-batch、异常处理、日志输出、多模块开发、多环境打包、缓存cache、爬虫、jwt、GraphQL、dubbo、zookeeper和Async等等📌
Stars: ✭ 1,819 (+1145.89%)
Mutual labels:  dubbo
Dubbo Go Pixiu
Based on the proxy gateway service of dubbo-go, it solves the problem that the external protocol calls the internal Dubbo cluster. At present, it supports HTTP and gRPC[developing].
Stars: ✭ 124 (-15.07%)
Mutual labels:  dubbo
Ssm Demo
🍌Spring+SpringMVC+Mybatis+easyUI实现简单的后台管理系统
Stars: ✭ 1,639 (+1022.6%)
Mutual labels:  dubbo
E3 Springboot
SpringBoot+Docker重构宜立方商城
Stars: ✭ 139 (-4.79%)
Mutual labels:  dubbo
Aeraki
Manage any layer 7 traffic in Istio Service Mesh.
Stars: ✭ 119 (-18.49%)
Mutual labels:  dubbo
Api Generator
Api Generator是一款可以自动解析Controller类抽取REST接口信息并自动上传YApi的IDEA插件。YApi好伴侣,从此维护文档再也不是事儿了!
Stars: ✭ 139 (-4.79%)
Mutual labels:  dubbo
Ibase4j
Spring,SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 1,548 (+960.27%)
Mutual labels:  dubbo
Dubbo2.5 Spring4 Mybastis3.2 Springmvc4 Mongodb Redis
dubbo2.5-spring4-mybastis3.2-springmvc4-mongodb-redis整合
Stars: ✭ 123 (-15.75%)
Mutual labels:  dubbo
Gatling Dubbo
A gatling plugin for running load tests on Apache Dubbo(https://github.com/apache/incubator-dubbo) and other java ecosystem.
Stars: ✭ 131 (-10.27%)
Mutual labels:  dubbo
Technology Talk
汇总java生态圈常用技术框架、开源中间件,系统架构、数据库、大公司架构案例、常用三方类库、项目管理、线上问题排查、个人成长、思考等知识
Stars: ✭ 12,136 (+8212.33%)
Mutual labels:  dubbo
Tropical Fish
Pragmatic 风格的 Java EE 后端开发脚手架,开箱即用。基于 SpringBoot,技术选型采用主流的框架(Mybatis-Plus,Redisson,Xxl-job,Swagger)。项目特点:自定义查询语法, 可以自由组装查询条件查询数据,配合代码生成模块,提高研发效率;自定义 service 方法级别的文档生成规则,在业务方法增加必要的注解,可生成方法调用树,快速把握复杂代码业务逻辑。
Stars: ✭ 142 (-2.74%)
Mutual labels:  dubbo

gohessian

Build Status codecov GoDoc Go Report Card license


Notice: When decoding, the java version of hessian will default skip and ignore non-exist fields. From the version of v1.6.0 , dubbo-go-hessian2 will skip non-exist fields too, while that before v1.6.0 will return errors.

It's a golang hessian library used by Apache/dubbo-go.

There is a big performance improvement, and some bugs fix for v1.6.0, thanks to micln, pantianying, zonghaishang, willson-chen, champly.

Feature List

hessian type mapping between Java and Go

Cross languages message definition should be careful, the following situations should be avoided:

  • define object that only exists in a special language
  • using various java exceptions (using error code/message instead)

So we can maintain a cross language type mapping:

hessian type java type golang type
null null nil
binary byte[] []byte
boolean boolean bool
date java.util.Date time.Time
double double float64
int int int32
long long int64
string java.lang.String string
list java.util.List slice
map java.util.Map map
object custom define object custom define struct
OTHER COMMON USING TYPE
big decimal java.math.BigDecimal github.com/dubbogo/gost/math/big/Decimal
big integer java.math.BigInteger github.com/dubbogo/gost/math/big/Integer
date java.sql.Date github.com/apache/dubbo-go-hessian2/java_sql_time/Date
date java.sql.Time github.com/apache/dubbo-go-hessian2/java_sql_time/Time
date all java8 sdk time github.com/apache/dubbo-go-hessian2/java8_time

reference

Basic Usage Examples

Encode To Bytes

type Circular struct {
	Value
	Previous *Circular
	Next     *Circular
}

type Value struct {
	Num int
}

func (Circular) JavaClassName() string {
	return "com.company.Circular"
}

c := &Circular{}
c.Num = 12345
c.Previous = c
c.Next = c

e := NewEncoder()
err := e.Encode(c)
if err != nil {
    panic(err)
}

bytes := e.Buffer()

Decode From Bytes

decodedObject, err := NewDecoder(bytes).Decode()
if err != nil {
    panic(err)
}
circular, ok := obj.(*Circular)
// ...

Customize Usage Examples

Encoding filed name

Hessian encoder default converts filed names of struct to lower camelcase, but you can customize it using hessian tag.

Example:

type MyUser struct {
	UserFullName      string   `hessian:"user_full_name"`
	FamilyPhoneNumber string   // default convert to => familyPhoneNumber
}

func (MyUser) JavaClassName() string {
	return "com.company.myuser"
}

user := &MyUser{
    UserFullName:      "username",
    FamilyPhoneNumber: "010-12345678",
}

e := hessian.NewEncoder()
err := e.Encode(user)
if err != nil {
    panic(err)
}

The encoded bytes of the struct MyUser is as following:

 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
 00000010  75 73 65 72 92 0e 75 73  65 72 5f 66 75 6c 6c 5f  |user..user_full_|
 00000020  6e 61 6d 65 11 66 61 6d  69 6c 79 50 68 6f 6e 65  |name.familyPhone|
 00000030  4e 75 6d 62 65 72 60 08  75 73 65 72 6e 61 6d 65  |Number`.username|
 00000040  0c 30 31 30 2d 31 32 33  34 35 36 37 38           |.010-12345678|

Decoding filed name

Hessian decoder finds the correct target field though comparing all filed names of struct one by one until matching.

The following example shows the order of the matching rules:

type MyUser struct {
	MobilePhone      string   `hessian:"mobile-phone"`
}

// You must define the tag of struct for lookup filed form encoded binary bytes, in this case:
// 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
// 00000010  75 73 65 72 91 0c 6d 6f  62 69 6c 65 2d 70 68 6f  |user..mobile-pho|
// 00000020  6e 65 60 0b 31 37 36 31  32 33 34 31 32 33 34     |ne`.17612341234|
//
// mobile-phone(tag lookup) => mobilePhone(lowerCameCase) => MobilePhone(SameCase) => mobilephone(lowercase)
// ^ will matched


type MyUser struct {
	MobilePhone      string
}

// The following encoded binary bytes will be hit automatically:
//
// 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
// 00000010  75 73 65 72 91 0b 6d 6f  62 69 6c 65 50 68 6f 6e  |user..mobilePhon|
// 00000020  65 60 0b 31 37 36 31 32  33 34 31 32 33 34        |e`.17612341234|
//
// mobile-phone(tag lookup) => mobilePhone(lowerCameCase) => MobilePhone(SameCase) => mobilephone(lowercase)
//                             ^ will matched
//
// 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
// 00000010  75 73 65 72 91 0b 4d 6f  62 69 6c 65 50 68 6f 6e  |user..MobilePhon|
// 00000020  65 60 0b 31 37 36 31 32  33 34 31 32 33 34        |e`.17612341234|
//
// mobile-phone(tag lookup) => mobilePhone(lowerCameCase) => MobilePhone(SameCase) => mobilephone(lowercase)
//                                                           ^ will matched
//
// 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
// 00000010  75 73 65 72 91 0b 6d 6f  62 69 6c 65 70 68 6f 6e  |user..mobilephon|
// 00000020  65 60 0b 31 37 36 31 32  33 34 31 32 33 34        |e`.17612341234|
//
// mobile-phone(tag lookup) => mobilePhone(lowerCameCase) => MobilePhone(SameCase) => mobilephone(lowercase)
//                                                                                    ^ will matched

hessian.SetTagIdentifier

You can use hessian.SetTagIdentifier to customize tag-identifier of hessian, which takes effect to both encoder and decoder.

Example:

hessian.SetTagIdentifier("json")

type MyUser struct {
	UserFullName      string   `json:"user_full_name"`
	FamilyPhoneNumber string   // default convert to => familyPhoneNumber
}

func (MyUser) JavaClassName() string {
	return "com.company.myuser"
}

user := &MyUser{
    UserFullName:      "username",
    FamilyPhoneNumber: "010-12345678",
}

e := hessian.NewEncoder()
err := e.Encode(user)
if err != nil {
    panic(err)
}

The encoded bytes of the struct MyUser is as following:

 00000000  43 12 63 6f 6d 2e 63 6f  6d 70 61 6e 79 2e 6d 79  |C.com.company.my|
 00000010  75 73 65 72 92 0e 75 73  65 72 5f 66 75 6c 6c 5f  |user..user_full_|
 00000020  6e 61 6d 65 11 66 61 6d  69 6c 79 50 68 6f 6e 65  |name.familyPhone|
 00000030  4e 75 6d 62 65 72 60 08  75 73 65 72 6e 61 6d 65  |Number`.username|
 00000040  0c 30 31 30 2d 31 32 33  34 35 36 37 38           |.010-12345678|

Using Java collections

By default, the output of Hessian Java impl of a Java collection like java.util.HashSet will be decoded as []interface{} in go-hessian2. To apply the one-to-one mapping relationship between certain Java collection class and your Go struct, examples are as follows:

//use HashSet as example
//define your struct, which should implements hessian.JavaCollectionObject
type JavaHashSet struct {
	value []interface{}
}

//get the inside slice value
func (j *JavaHashSet) Get() []interface{} {
	return j.value
}

//set the inside slice value
func (j *JavaHashSet) Set(v []interface{}) {
	j.value = v
}

//should be the same as the class name of the Java collection
func (j *JavaHashSet) JavaClassName() string {
	return "java.util.HashSet"
}

func init() {
        //register your struct so that hessian can recognized it when encoding and decoding
	SetCollectionSerialize(&JavaHashSet{})
}

Notice for inheritance

go-hessian2 supports inheritance struct, but the following situations should be avoided.

  • Avoid fields with the same name in multiple parent struct

The following struct C have inherited field Name(default from the first parent), but it's confused in logic.

type A struct { Name string }
type B struct { Name string }
type C struct {
	A
	B
}
  • Avoid inheritance for a pointer of struct

The following definition is valid for golang syntax, but the parent will be nil when create a new Dog, like dog := Dog{}, which will not happen in java inheritance, and is also not supported by go-hessian2.

type Dog struct {
	*Animal
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].