Code Monkey home page Code Monkey logo

Comments (3)

Linyuzai avatar Linyuzai commented on September 26, 2024

依赖名称:concept-netty-loadbalance-spring-boot-starter

依赖版本:2.3.0 、 2.3.2

问题描述:使用rabbimq转发UserMessage消息 BaseMessageCodecAdapter.getForwardMessageDecoder 方法下的 JacksonForwardMessageDecoder.readTree(Object message)抛出异常。mq转发消息Object message 类型(org.springframework.amqp.core.Message)

代码示例: 修复重写方法: @SneakyThrows protected JsonNode readTree(Object message) { if (message instanceof String strMessage) { return objectMapper.readTree(strMessage); } if (message instanceof Message mqMessage) { return objectMapper.readTree((mqMessage.getBody())); } if (message instanceof ByteBuffer byteBuffer) { return objectMapper.readTree(byteBuffer.array()); } if (message instanceof byte[]) { return objectMapper.readTree((byte[]) message); } throw new MessageDecodeException(message); }

我这边 2.3.2 没有复现,rabbitmq message 的处理在 RabbitMessageCodecAdapter,能提供更详细的信息吗

from concept.

fenfeiyunluo avatar fenfeiyunluo commented on September 26, 2024

我测试了一下, 确认在2.3.2中没有复现了。另外提一个改进的小建议:同一个类的decode 方法的else逻辑, 如果传递的是json字符串, jar中使用的payloadNode.asText() 方法会传递为空字符串, 建议的改进如下:
TextMessage decoded = new TextMessage();
decoded.setHeaders(headers);
if (payloadNode.isTextual()) {
decoded.setPayload(payloadNode.asText());
} else if (payloadNode.isObject()) {
decoded.setPayload(payloadNode.toString());
}
return decoded;
判断传递的是字符串还是对象, 进行分别处理。

from concept.

Linyuzai avatar Linyuzai commented on September 26, 2024

我测试了一下, 确认在2.3.2中没有复现了。另外提一个改进的小建议:同一个类的decode 方法的else逻辑, 如果传递的是json字符串, jar中使用的payloadNode.asText() 方法会传递为空字符串, 建议的改进如下:
TextMessage decoded = new TextMessage();
decoded.setHeaders(headers);
if (payloadNode.isTextual()) {
decoded.setPayload(payloadNode.asText());
} else if (payloadNode.isObject()) {
decoded.setPayload(payloadNode.toString());
}
return decoded;
判断传递的是字符串还是对象, 进行分别处理。

2.3.3版本已经修改

from concept.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.