【问题标题】:ErrorHandling in SpringXDSpring XD 中的错误处理
【发布时间】:2016-05-19 18:54:25
【问题描述】:

我已将 Redis 配置为我的 spring-xd 设置的 MessageBus。当我的流失败时,数据被推送到错误队列。我正在尝试将它们读回并将它们推回目标队列。但我没有看到我的接收器模块接收数据。一些可以帮助我了解我哪里出错了。

代码片段。

public RedisTemplate<String, byte[]> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
  final RedisTemplate<String, byte[]> template = new RedisTemplate<String, byte[]>();
  template.setConnectionFactory(redisConnectionFactory);
  template.setKeySerializer(new StringRedisSerializer());
  template.setEnableDefaultSerializer(false);
  return template;
}

List<String> listOfKeys = new ArrayList<>();
Set<byte[]> keys = redisTemplate.getConnectionFactory().getConnection().keys("ERRORS*".getBytes());
for (byte[] data : keys) {
  listOfKeys.add(new String(data, 0, data.length));
}
for (String errorQueue : listOfKeys) {
    String destinationQueue = errorQueue.replace("ERRORS:", EMPTY_STRING);
    Long size = redisTemplate.opsForList().size(errorQueue);
    for (int i = 0; i < size; i++) {
        byte[] errorEvt = redisTemplate.opsForList().rightPop(errorQueue);
        redisTemplate.opsForList().leftPush(destinationQueue, errorEvt);
    }
}

【问题讨论】:

    标签: java redis spring-xd


    【解决方案1】:

    快速浏览一下您的代码,它应该可以正常工作;建议你运行redis-cli,然后输入monitor查看redis流量。

    编辑

    在下面回答您的评论 - 这取决于您的内容类型。如果是简单的文字,还是比较简单的:

    "\xff\x01\x0bcontentType\x00\x00\x00\x0c\"text/plain\"2016-05-20 10:11:07"
    

    第一部分是标头,您可以使用 XD 的EmbeddedHeadersMessageConverter 对其进行解码。

    如果你的payload是一个java对象,它会被总线使用kryo序列化。

    【讨论】:

    • 谢谢@Gary。我发现了这个问题。我的目标队列缺少前缀“queue.”。它必须是destinationQueue =“队列”。 + errorQueue.replace("错误:", EMPTY_STRING);你能帮我如何将errorEvt (byte[] errorEvt = redisTemplate.opsForList().rightPop(errorQueue);) 转换为我的实际有效负载,我想记录味精以进行测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多