我如何在春季集成流中处理旁观的消息
我在春季集成方面遇到了一些问题。
我有一个错误的频道,该通道应该消耗一个错误的队列,以防其他流量有错误,该处理程序允许我们以非常特定的格式记录一些重要数据,然后丢弃该消息。
问题是,该流程被配置为接收特定的消息类型,例如失败的Message类。
每当消耗消息时,我都会得到一个类铸造例外,说[b不能被铸造为失败
。
因此,在进行了一些研究之后,我实施了以下变压器:
private FailedMessage parseFailedMessage(byte[] genericMessage){
try {
ByteArrayInputStream in = new ByteArrayInputStream(genericMessage);
ObjectInputStream is = new ObjectInputStream(in);
return (FailedMessage) is.readObject();
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException("An unexpected error occurred parsing FailedMessage", e);
}
}
IntegrationFlow Spec是:
@Bean
public IntegrationFlow errorHandlingFlow(XmlMessageTransformer transformer) {
return IntegrationFlows.from("ErrorChannel")
.transform(this::parseFailedMessage)
.<FailedMessage>handle((p, h) -> {
processFailedMessage(p, transformer);
return p;
})
.channel("discard")
.get();
}
这是处理此类消息的可接受方法,还是有一种方法可以自动化转换步骤?
I'm having some issues with Spring Integration.
I have an error channel that is supposed to consume an error dedicated queue in case other flows have an error, this handler allows us to log some important data in a very specific format, and then the message is discarded.
The problem is, that this flow is configured to receive a specific message type, like a FailedMessage class.
Whenever the message is consumed, I get a class cast exception saying that [B cannot be cast to FailedMessage
.
So, after doing some research I implemented the following transformer:
private FailedMessage parseFailedMessage(byte[] genericMessage){
try {
ByteArrayInputStream in = new ByteArrayInputStream(genericMessage);
ObjectInputStream is = new ObjectInputStream(in);
return (FailedMessage) is.readObject();
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException("An unexpected error occurred parsing FailedMessage", e);
}
}
And the IntegrationFlow spec is :
@Bean
public IntegrationFlow errorHandlingFlow(XmlMessageTransformer transformer) {
return IntegrationFlows.from("ErrorChannel")
.transform(this::parseFailedMessage)
.<FailedMessage>handle((p, h) -> {
processFailedMessage(p, transformer);
return p;
})
.channel("discard")
.get();
}
Is this an acceptable way to handle this kind of message or there's a way to automatize the transform step?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论