英文:
Describe a DynamoDB table using Apache Camel
问题
我正在尝试使用Apache Camel的aws2 DynamoDB组件。其中有一个操作叫做DescribeTable
。我正在尝试着使用它。我有一个类似这样的Camel REST API ->
.post("dynamodb-describe-table")
.route()
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelAwsDdbTableName", "user");
}
})
.toD("aws2-ddb://user?accessKey=insert&secretKey=insert&region=us-east-1&operation=DescribeTable")
.endRest();
这个操作成功运行了,但是响应却是空的。为什么会发生这种情况呢?
英文:
I am trying to use the Apache Camel aws2 DyanamoDB component. In that there is a operation DescribeTable
. I was trying that out.I have a camel rest API like so ->
.post("dynamodb-describe-table")
.route()
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelAwsDdbTableName", "user");
}
})
.toD("aws2-ddb://user?accessKey=insert&secretKey=insert&region=us-east-1&operation=DescribeTable")
.endRest();
This operation is run successfully but the response is null. Why is this happening?
答案1
得分: 0
操作DescribeTable
不返回主体。所有属性都以Message
标头的形式返回。
此操作返回的所有标头在AWS DynamoDB文档中列出。
您有许多选项可以创建主体,例如使用MVEL:
.transform().mvel("{" +
"'tableSize': exchange.in.headers.CamelAwsDdbTableSize," +
"'status': 'exchange.in.headers.Cam
elAwsDdbTableStatus'" +
"}")
或者使用Processor
:
.process( exchange ->
exchange.getIn().setBody(
new HashMap<String, Object>(){{
put("tableSize", exchange.getMessage().getHeader("CamelAwsDdbTableSize"));
put("status", exchange.getMessage().getHeader("CamelAwsDdbTableStatus"));
// ...
}}
)
)
在toD()
和endRest()
之间。
顺便说一句,我在您的URI中看不到任何动态部分,您应该可以只使用to()
,通常这样做会更快。
英文:
Operation DescribeTable
does not return body. All attributes are returned in form of Message
headers.
All headers returned by this operation are listed in AWS DynamoDB documentation.
You have many options to create body, eg. with MVEL:
.transform().mvel("{" +
"'tableSize': exchange.in.headers.CamelAwsDdbTableSize," +
"'status': 'exchange.in.headers.CamelAwsDdbTableStatus'" +
"}")
Or Processor
:
.process( exchange ->
exchange.getIn().setBody(
new HashMap<String, Object>(){{
put("tableSize", exchange.getMessage().getHeader("CamelAwsDdbTableSize"));
put("status", exchange.getMessage().getHeader("CamelAwsDdbTableStatus"));
// ...
}}
)
)
Between your toD()
and endRest()
.
BTW I don't see any dynamic part in your URI, you should be able to use just to()
, which i generally faster.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论