我如何使用 camel-ddb 来持久化 json payload
How do I use camel-ddb to persist json payload
我在 dynamodb (EU-WEST-1) 中创建了 table 并且我创建了一个骆驼路线以将 json 有效载荷放入 table.
我的路线是这样的:
String dynamoDbEndpoint = String.format("aws-ddb://tablename?accessKey=%s&secretKey=RAW(%s)&tableName=tablename&amazonDdbEndpoint=dynamodb.eu-west-1.amazonaws.com",awsAccessKey,awsSecretKey);
from("direct:ipg-queue").to(dynamoDbEndpoint)
我收到错误消息:
com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'item' failed to satisfy constraint: Member must not be null (Service: AmazonDynamoDB; Status Code: 400; Error Code: ValidationException; Request ID: 0AVSR54LRTOG3U0TTC5B1QO4KBVV4KQNSO5AEMVJF66Q9ASUAAJG)
有效负载示例是:
{"accountNumber":"123456789","customerName":"John Smith","id":"8422b9e0-739b-4d19-9291-037b68344068"}
表示为字符串。
我在做一些蠢事,但想不通...
原来是我傻了。您只需要在交换中设置 CamelAwdDbItem header。我在 dynamo db 端点之前将以下过程块添加到我的路线,然后我去了...
.unmarshal()
.json(JsonLibrary.Gson, Map.class)
.process((Exchange exchange) -> {
Map body = (Map) exchange.getIn()
.getBody();
Map<String, AttributeValue> newBody = new HashMap();
for(Object key : body.keySet()) {
newBody.put(key.toString(), new AttributeValue(body.get(key).toString()));
}
exchange.getIn().setHeader("CamelAwsDdbItem", newBody);
})
我还把 &operation=PutItem
放到端点定义的末尾。
我在 dynamodb (EU-WEST-1) 中创建了 table 并且我创建了一个骆驼路线以将 json 有效载荷放入 table.
我的路线是这样的:
String dynamoDbEndpoint = String.format("aws-ddb://tablename?accessKey=%s&secretKey=RAW(%s)&tableName=tablename&amazonDdbEndpoint=dynamodb.eu-west-1.amazonaws.com",awsAccessKey,awsSecretKey);
from("direct:ipg-queue").to(dynamoDbEndpoint)
我收到错误消息:
com.amazonaws.AmazonServiceException: 1 validation error detected: Value null at 'item' failed to satisfy constraint: Member must not be null (Service: AmazonDynamoDB; Status Code: 400; Error Code: ValidationException; Request ID: 0AVSR54LRTOG3U0TTC5B1QO4KBVV4KQNSO5AEMVJF66Q9ASUAAJG)
有效负载示例是:
{"accountNumber":"123456789","customerName":"John Smith","id":"8422b9e0-739b-4d19-9291-037b68344068"}
表示为字符串。
我在做一些蠢事,但想不通...
原来是我傻了。您只需要在交换中设置 CamelAwdDbItem header。我在 dynamo db 端点之前将以下过程块添加到我的路线,然后我去了...
.unmarshal()
.json(JsonLibrary.Gson, Map.class)
.process((Exchange exchange) -> {
Map body = (Map) exchange.getIn()
.getBody();
Map<String, AttributeValue> newBody = new HashMap();
for(Object key : body.keySet()) {
newBody.put(key.toString(), new AttributeValue(body.get(key).toString()));
}
exchange.getIn().setHeader("CamelAwsDdbItem", newBody);
})
我还把 &operation=PutItem
放到端点定义的末尾。