背景:
A发消息给B系统,A、B应用的编码均为UTF-8,但是B收到的消息出现中文乱码。
A发送消息的方式:
new Message(TOPIC, TAG, null, (messageContent.toString()).getBytes())
这里消息接受二进制byte数据,我们把消息string转换为byte的时候,默认使用了getBytes(),未指定编码方式,getBytes()方法的注释如下:Encodes this {@code String} into a sequence of bytes using the platform’s default charset, storing the result into a new byte array.也就是会使用平台默认编码,查看StringCoding.encode方法中的Charset.defaultCharset().name()方法:
继续阅读 →