我正在开发一个系统,我需要在Cassandra数据库中存储Avro Schemas.所以在Cassandra,我们将存储这样的东西SchemaId AvroSchema1 some schema2 another schema现在假设...
![](https://oss.womengda.net/imgfile/2310/1ER0602224360-33462.jpg)
我正在开发一个系统,我需要在Cassandra数据库中存储Avro Schemas.所以在Cassandra,我们将存储这样的东西
SchemaId AvroSchema
1 some schema
2 another schema
现在假设我在Cassandra的上表中插入另一行,现在表格就像这样 –
SchemaId AvroSchema
1 some schema
2 another schema
3 another new schema
只要我在上表中插入一个新行 – 我需要告诉我的Java程序去拉新的模式ID和相应的模式.
解决这类问题的正确方法是什么?
我知道,一种方法是每隔几分钟进行一次轮询,让我们说每5分钟我们就会从上表中提取数据,但这不是每5分钟解决这个问题的正确方法,我正在拉动是否有任何新的架构..
但除此之外还有其他解决方案吗?
我们可以使用Apache Zookeeper吗?或者Zookeeper不适合这个问题?
或任何其他解决方案?
我正在运行Apache Cassandra 1.2.9
解决方法:
一些解决方案
>使用数据库触发器:Cassandra 2.0有一些触发器支持,但看起来它不是最终的,并且根据本文可能会在2.1中稍微改变:http://www.datastax.com/dev/blog/whats-new-in-cassandra-2-0-prototype-triggers-support.触发器是一种常见的解决方案.
>你提出了民意调查,但这并不总是一个糟糕的选择.特别是如果你有一些东西标记该行还没有被拉动,那么你可以从Cassandra中拉出新的行.如果查询费用不高,那么每5分钟拉一次对于Cassandra或任何数据库来说都不是明智之举.如果在很少的基础上插入新行,则此选项可能不太好.
Zookeeper不是一个完美的解决方案,请看这个引用:
Because watches are one time triggers and there is latency between
getting the event and sending a new request to get a watch you cannot
reliably see every change that happens to a node in ZooKeeper. Be
prepared to handle the case where the znode changes multiple times
between getting the event and setting the watch again. (You may not
care, but at least realize it may happen.)
报价来自:http://zookeeper.apache.org/doc/r3.4.2/zookeeperProgrammers.html#sc_WatchRememberThese
本文标题为:java – 每当有任何新行或任何新更新时从Cassandra数据库中拉出来?
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- Spring注解驱动之BeanFactoryPostProcessor原理解析 2023-06-06
- Java模拟实现扑克牌洗牌和发牌的示例代码 2023-05-25
- java Object转byte与byte转Object方式 2023-04-18
- Mybatis Log Plugin的使用方式 2022-10-24
- Java实现经典游戏Flappy Bird的示例代码 2022-11-05
- Java基础学习之IO流应用案例详解 2023-05-18
- Java数据结构之图的基础概念和数据模型详解 2023-06-30
- 通过FeignClient如何获取文件流steam is close问题 2023-01-09
- 如何将Java对象转换为JSON实例详解 2023-04-12
- springboot如何设置请求参数长度和文件大小限制 2023-06-06