Comments (1)
2.6.0的版本可以通过下面的方式修改下发的消息,可以试一下
public void sendEntity(Entity entity) {
//这里需要指定Class用于数据转发之后的反序列化
ObjectMessage message = new ObjectMessage(entity, Entity.class);
concept.send(message);
}
//注入一个编解码适配器给每个消息设置不同的数据
@Component
public class WsEntityCodecAdapter extends WebSocketMessageCodecAdapter {
@Override
public MessageEncoder getClientMessageEncoder(MessageEncoder encoder) {
//自定义编码器
return new EntityMessageEncoder(encoder);
}
@RequiredArgsConstructor
public static class EntityMessageEncoder implements MessageEncoder {
private final MessageEncoder encoder;
@Override
public Object encode(Message message, Connection connection, ConnectionLoadBalanceConcept concept) {
Object payload = message.getPayload();
//如果是实体对象
if (payload instanceof Entity) {
//新建一个实体对象设置内容以及编号
Entity newEntity = new Entity();
newEntity.setContent(((Entity) payload).getContent());
newEntity.setId(UUID.randomUUID().toString());
//新建一个消息对象设置消息头和新实体对象
ObjectMessage newMessage = new ObjectMessage();
newMessage.getHeaders().putAll(message.getHeaders());
newMessage.setPayload(newEntity);
//传入新消息对象
return encoder.encode(newMessage, connection, concept);
}
return encoder.encode(message, connection, concept);
}
}
}
from concept.
Related Issues (20)
- 当发送base64文件在消息中时socket会被关闭 HOT 2
- 使用RABBIT_FANOUT转发消息解析异常 HOT 3
- 启动多个服务实例,实例之间无法连接 HOT 11
- 如果发送消息量过大或者base64图片的时候会直接关闭socket能够通过配置解决? HOT 16
- 支持不用注册中心的版本吗? HOT 1
- 使用websocket网关服务报readAddress(..) failed: Connection reset by peer HOT 12
- 长文本支持要怎么设置 HOT 1
- 异步回调转为同步返回 HOT 5
- 发现发送消息会一直占用 发生java.lang.OutOfMemoryError: Java heap space HOT 12
- 消息转发json转义 HOT 13
- websocket连接过多 HOT 2
- 如何主动关闭集群其它机器的 websocket 连接 HOT 2
- springboot3.2.4 Download组件报错 HOT 2
- SpringBoot 3.2.5 Download组件报错
- 自身实例去连接其他实例时报404 HOT 8
- 如果有server.servlet.context-path的话会导致自身实例连接订阅其他实例失败且PathMessage全部变成死信消息导致接收不到 HOT 3
- concept-downlaod 下载文件可以指定目录么, HOT 7
- concept-downlaod可以下载到服务器指定路径 HOT 34
- 大量websocket连接优化 HOT 35
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from concept.