如何使用Apache Camel扫描DynamoDB表格?

huangapple go评论88阅读模式
英文:

How to scan a dynamodb table using apache camel?

问题

I have a camel rest api which scans a DynamoDb table. The code is like so ->

.post("dynamodb-scan-table")
   .route()
  .toD("aws2-ddb://user?accessKey=insert&secretKey=insert&region=us-east-1&operation=Scan")
  .endRest();

This returns all the items in my table. My problem is how to scan the table based on a certain condition. In the camel docs, it is given that there is a header CamelAwsDdbScanFilter which is of the type Map<String, Condition> needs to be set in order to achieve the solution for my problem. I have a table of users and suppose I want to retrieve all the users with FirsName = Will. How do I implement the Map<String, Condition> in order to achieve this? Basically I am not sure what to put in the Condition of the map.

英文:

I have a camel rest api which scans a DynamoDb table. The code is like so ->

.post(&quot;dynamodb-scan-table&quot;)
   .route()
  .toD(&quot;aws2-ddb://user?accessKey=insert&amp;secretKey=insert&amp;region=us-east-1&amp;operation=Scan&quot;)
  .endRest();

This returns all the items in my table. My problem is how to scan the table based on a certain condition. In the camel docs, it is given that there is a header CamelAwsDdbScanFilter which is of the type Map&lt;String, Condition&gt; needs to be set in order to achieve the solution for my problem. I have a table of users and suppose I want to retrieve all the users with FirsName = Will. How do I implement the Map&lt;String, Condition&gt; in order to achieve this? Basically I am not sure what to put in the Condition of the map.

答案1

得分: 0

你可以在ScanCommandTest中找到示例用法。

对于条件 FirstName eq Will,过滤器可以是这样的:

exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, new HashMap<String, Condition>(){{
    put("FirsName", new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS("Will")));
}});
英文:

You can find example usage in ScanCommandTest.

For condition FirstName eq Will the filter could be something like:

exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, new HashMap&lt;String, Condition&gt;(){{
    put(&quot;FirsName&quot;, new Condition()
            .withComparisonOperator(ComparisonOperator.EQ)
            .withAttributeValueList(new AttributeValue().withS(&quot;Will&quot;)));
}});

huangapple
  • 本文由 发表于 2020年7月28日 07:21:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63124977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定