【问题标题】:Streaming Data into Google BigQuery Tables : problems using InsertId to De-Duplicate Records将数据流式传输到 Google BigQuery 表中:使用 InsertId 消除重复记录的问题
【发布时间】:2019-12-25 21:24:01
【问题描述】:

我们正在使用 Camel BigQuery API(版本 2.20)将记录从 ActiveMQ 服务器(版本 5.14.3)上的消息队列流式传输到 Google BigQuery 表中.

我们已经在主站点上运行的 Spring 框架 中将流式传输机制实现并部署为 XML 路由定义,它似乎运行良好。

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        ./spring-beans.xsd
        http://camel.apache.org/schema/spring
        ./camel-spring.xsd">

    <!--
    # ==========================================================================
    # ActiveMQ JMS Bean Definition
    # ==========================================================================
    -->
    <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory">
            <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL" value="nio://192.168.10.10:61616?jms.useAsyncSend=true" />
                <property name="userName"  value="MyAmqUserName" />
                <property name="password"  value="MyAmqPassword" />
            </bean>
        </property>
    </bean>

    <!--
    # ==========================================================================
    # GoogleBigQueryComponent
    # https://github.com/apache/camel/tree/master/components/camel-google-bigquery
    # ==========================================================================
    -->
    <bean id="gcp" class="org.apache.camel.component.google.bigquery.GoogleBigQueryComponent">
        <property name="connectionFactory">
            <bean class="org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory">
                <property name="credentialsFileLocation" value="MyDir/MyGcpKeyFile.json" />
            </bean>
        </property>
    </bean>

    <!--
    # ==========================================================================
    # Main Context Bean Definition
    # ==========================================================================
    -->
    <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring" >

        <!--
        # ==================================================================
        # Message Route :
        # 1. consume messages from my AMQ queue
        # 2. set the InsertId / INSERT_ID (it is not clear which is the correct one)
        # 3. write message to Google BigQuery table
        # see https://github.com/apache/camel/blob/master/components/camel-google-bigquery/src/main/docs/google-bigquery-component.adoc
        # ==================================================================
        <log message="${headers} | ${body}" />
        -->
        <route>
            <from uri="jms:my.amq.queue.of.output.data.for.gcp?acknowledgementModeName=DUPS_OK_ACKNOWLEDGE&amp;concurrentConsumers=20" />
            <setHeader headerName="CamelGoogleBigQuery.InsertId">
                <simple>${header.KeyValuePreviouslyGenerated}</simple>
            </setHeader>
            <setHeader headerName="GoogleBigQueryConstants.INSERT_ID">
                <simple>${header.KeyValuePreviouslyGenerated}</simple>
            </setHeader>
            <to uri="gcp:my_gcp_project:my_bq_data_set:my_bq_table" />
        </route>

    </camelContext>

</beans>

为了提高(更好)可用性,我们现在已将相同的实施部署到我们的备份站点,流式传输到相同的目标 BigQuery 表。正如预期的那样,相同的记录从两个站点流式传输到同一个表中,存在重复记录。为了消除记录重复,我们正在尝试遵循此处给出的指导:

https://camel.apache.org/staging/components/latest/google-bigquery-component.html

Message Headers 部分建议使用合适的运行时键值设置名为 CamelGoogleBigQuery.InsertId 的消息标头。

但在同一页面下方,确保数据一致性部分建议设置 GoogleBigQueryConstants.INSERT_ID

我们检查了我们的主服务器和备用服务器在同一时区 (UTC) 中运行,并且我们正在生成我们认为合适的运行时唯一键:一个包含 UNIX 时间到最近的字符串第二个。

上面的代码示例表明我们已经尝试了这两种方法,但对我们目标 BigQuery 表中的数据的审查表明这两种方法似乎都不起作用,即我们仍然有重复的记录。

问题

  1. 我们在上面的代码中设置 InsertID / INSERT_ID 的方式是否有错误?
  2. 您是否使用过 Camel Google BigQuery API 将数据流式传输到 BigQuery 中?
  3. 如果是,您是否成功使用了 InsertId / INSERT_ID 去重机制?如果是,是哪一个以及如何?
  4. 您观察到了哪些重复数据删除时间窗口?

【问题讨论】:

    标签: google-bigquery apache-camel spring-jms spring-camel


    【解决方案1】:

    GoogleBigQueryConstants.INSERT_ID 是字符串常量,值为CamelGoogleBigQueryInsertId

    像这样使用它:

    <setHeader headerName="CamelGoogleBigQueryInsertId">
        <simple>${header.KeyValuePreviouslyGenerated}</simple>
    </setHeader>
    

    演示此行为的单元测试在这里:InsertIdTest.java


    关于这些头文件的文档有点过时,我已经修复了它,正确的版本可以在google-bigquery-component.adoc 中找到。很快就会在网站上发布。

    【讨论】:

    • 重新测试和审查结果的时间比预期的要长,但非常感谢,“CamelGoogleBigQueryInsertId”工作得很好 - 展示了文档中的一个小点是如何成就或破坏某些东西的!再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2018-10-13
    • 2021-06-28
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2022-10-24
    • 1970-01-01
    相关资源
    最近更新 更多