简体   繁体   中英

Describe a DynamoDB table using Apache Camel

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM