描述使用Apache Camel的DynamoDB表。

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

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.

huangapple
  • 本文由 发表于 2020年7月26日 06:27:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/63094184.html
匿名

发表评论

匿名网友

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

确定