我正在向 channel 发送消息,但必须为每个客户端修改它。
有谁有这方面的经验吗?
最佳答案
给你。
Spring 为传入和传出 channel 提供拦截器。 因此,只需添加一个拦截器,您就可以捕获每条传入和传出的消息并执行您想做的任何操作。
首先是你的配置:
...
@Autowired
private InboundMessagesChannelInterceptor inboundMessagesChannelInterceptor;
@Autowired
private OutboundMessagesChannelInterceptor outboundMessagesChannelInterceptor;
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
registration.interceptors(inboundMessagesChannelInterceptor);
}
@Override
public void configureClientOutboundChannel(ChannelRegistration registration) {
registration.interceptors(outboundMessagesChannelInterceptor);
}
...
和你的拦截器:
@Component
public class OutboundMessagesChannelInterceptor implements ChannelInterceptor {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
// modify your message as needed
return message;
}
}
就是这样。
关于java - 如何在 Spring Boot 中单独修改 channel 内每个接收者的每个代理消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56834604/