This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 2dbe14d camel-aws2-ddb: added data examples of PutItem and UpdateItem
(#6944)
2dbe14d is described below
commit 2dbe14d863eaaf9b7058f851162690b4ee810643
Author: Neo <[email protected]>
AuthorDate: Wed Feb 16 18:52:51 2022 +1100
camel-aws2-ddb: added data examples of PutItem and UpdateItem (#6944)
* added create and update operation data example
* updated the example to register a DynamoDbClient
Co-authored-by: Neo Xu <[email protected]>
---
.../src/main/docs/aws2-ddb-component.adoc | 60 ++++++++++++++++++----
1 file changed, 50 insertions(+), 10 deletions(-)
diff --git
a/components/camel-aws/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc
b/components/camel-aws/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc
index 11fae5d..3956a12 100644
--- a/components/camel-aws/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc
+++ b/components/camel-aws/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc
@@ -266,8 +266,25 @@ URI:
[source,java]
----------------------------------------------------
-from("direct:start")
-.to("aws2-ddb://domainName?amazonDDBClient=#client");
+public class MyRouteBuilder extends RouteBuilder {
+
+ private String accessKey = "myaccessKey";
+ private String secretKey = "secretKey";
+
+ @Override
+ public void configure() throws Exception {
+
+ DynamoDbClient client = DynamoDbClient.builder()
+ .region(Region.AP_SOUTHEAST_2)
+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey,
secretKey)))
+ .build();
+
+ getCamelContext().getRegistry().bind("client", client);
+
+ from("direct:start")
+ .to("aws2-ddb://domainName?amazonDDBClient=#client");
+ }
+}
----------------------------------------------------
The `#client` refers to a `DynamoDbClient` in the
@@ -296,15 +313,38 @@ Registry.
[source,java]
--------------------------------------------------------------------------------
+Map<String, AttributeValue> attributeMap = new HashMap<>();
+attributeMap.put("partitionKey", AttributeValue.builder().s("3000").build());
+attributeMap.put("id", AttributeValue.builder().s("1001").build());
+attributeMap.put("barcode",
AttributeValue.builder().s("9002811220001").build());
+
+from("direct:start")
+ .setHeader(Ddb2Constants.OPERATION, constant(Ddb2Operations.PutItem))
+ .setHeader(Ddb2Constants.CONSISTENT_READ, constant("true"))
+ .setHeader(Ddb2Constants.RETURN_VALUES, constant("ALL_OLD"))
+ .setHeader(Ddb2Constants.ITEM, constant(attributeMap))
+ .setHeader(Ddb2Constants.ATTRIBUTE_NAMES, constant(attributeMap.keySet()))
+ .to("aws2-ddb://" + tableName + "?amazonDDBClient=#client");
+--------------------------------------------------------------------------------
+
+- UpdateItem: this operation will update an entry into DynamoDB
+
+[source,java]
+--------------------------------------------------------------------------------
+Map<String, AttributeValueUpdate> attributeMap = new HashMap<>();
+attributeMap.put("partitionKey",
AttributeValueUpdate.builder().value(AttributeValue.builder().s("3000").build()).build());
+attributeMap.put("sortKey",
AttributeValueUpdate.builder().value(AttributeValue.builder().s("1001").build()).build());
+attributeMap.put("borcode",
AttributeValueUpdate.builder().value(AttributeValue.builder().s("900281122").build()).build());
+
+Map<String, AttributeValue> keyMap = new HashMap<>();
+keyMap.put("partitionKey", AttributeValue.builder().s("3000").build());
+keyMap.put("sortKey", AttributeValue.builder().s("1001").build());
+
from("direct:start")
- .setHeader(Ddb2Constants.OPERATION, Ddb2Operations.PutItem)
- .setHeader(Ddb2Constants.CONSISTENT_READ, "true")
- .setHeader(Ddb2Constants.RETURN_VALUES, "ALL_OLD")
- .setHeader(Ddb2Constants.ITEM, attributeMap)
- .setHeader(Ddb2Constants.ATTRIBUTE_NAMES, attributeMap.keySet());
- .to("aws2-ddb://" + tableName + "?keyAttributeName=" + attributeName +
"&keyAttributeType=" + KeyType.HASH
- + "&keyScalarType=" + ScalarAttributeType.S
- + "&readCapacity=1&writeCapacity=1");
+ .setHeader(Ddb2Constants.OPERATION, constant(Ddb2Operations.UpdateItem))
+ .setHeader(Ddb2Constants.ITEM, constant(attributeMap))
+ .setHeader(Ddb2Constants.KEY, constant(keyMap))
+ .to("aws2-ddb://" + tableName + "?amazonDDBClient=#client");
--------------------------------------------------------------------------------
Maven users will need to add the following dependency to their pom.xml.