Reputation: 1101
I have a simple route that moves messages from SQS into my local database:
class DlrSqsToDb extends RouteBuilder {
"""aws-sqs://123467890/test-queue?amazonSQSClient=%23awsSqsClient&amazonSQSEndpoint=https://sqs.eu-west-1.amazonaws.com""" ==> {
setHeader("dlr_body", body)
setHeader("msgid", "someid")
to("sql:insert into camel_test (msgid, dlr_body) VALUES (:#msgid,:#dlr_body)?dataSource=dataSource")
}
}
I want to throttle this so that sqs handles peaks, but so that the load on my local database is limited. I can do a delay() for example, but not throttle():
....
"""aws-sqs://123467890/test-queue?amazonSQSClient=%23awsSqsClient&amazonSQSEndpoint=https://sqs.eu-west-1.amazonaws.com""" ==> {
delay(3000)
....
works but
....
"""aws-sqs://123467890/test-queue?amazonSQSClient=%23awsSqsClient&amazonSQSEndpoint=https://sqs.eu-west-1.amazonaws.com""" ==> {
throttle(1)
....
cannot compile:
[error] found : Int(1)
[error] required: org.apache.camel.scala.Frequency
[error] throttle(1)
and
....
"""aws-sqs://123467890/test-queue?amazonSQSClient=%23awsSqsClient&amazonSQSEndpoint=https://sqs.eu-west-1.amazonaws.com""" ==> {
throttle(new org.apache.camel.scala.Frequency(1,3000))
....
compiles but crashes with an error:
.... because of Definition has no children on Throttle[{1} request per 3000 millis -> []]
what is the proper syntax for using throttle in scala?
Upvotes: 0
Views: 299
Reputation: 1247
Try wrapping the next 'to' in the block of the throttle like so:
"""aws-sqs://123467890/test-queue?amazonSQSClient=%23awsSqsClient&amazonSQSEndpoint=https://sqs.eu-west-1.amazonaws.com""" ==> {
setHeader("dlr_body", body)
setHeader("msgid", "someid")
throttle(1 per (3 seconds)) {
to("sql:insert into camel_test (msgid, dlr_body) VALUES (:#msgid,:#dlr_body)?dataSource=dataSource")
}
}
This is untested, but I suspect it's because of the block syntax that you need to be explicit about making the final 'to' a child of throttle. Sadly I found camels scala dsl to be very fussy about the ordering of statements but very lax about what actually compiles.
Upvotes: 1