Apache Camel-如何在Java中使用属性配置端点

时间:2018-10-01 08:19:32

标签: java apache-camel amq

这是我下面使用XML完美运行的骆驼路线

<route id="someId">
            <from id="_from" uri="{{consumer.serviceName}}:queue:{{consumer.notificationQueue}}?{{consumer.queryParams}}"/>
            <log loggerRef="loggerId" message="Messages throttling from Queue"/>
            <throttle prop:timePeriodMillis="{{throttle.timePeriod}}">
                <constant>{{throttle.maximumRequestsPerSecond}}</constant>
                <log loggerRef="logger" message="Consuming notification message from Queue {{consumer.myQueue}} : ${body}"/> 
                <bean id="beanId" method="process" ref="MyProcessor"/>
            </throttle>
        </route>

现在,我想用Java编写类似的驼峰端点。 您能告诉我如何在其中添加对数和限制属性吗?

MyProcessor  messageProcessor;
String Uri = serviceName + ":queue:" + queueName + "?" + queryParams;
Endpoint ep = camelContext.getEndpoint(Uri);
Consumer consumer = ep.createConsumer(messageProcessor);
consumer.start();

1 个答案:

答案 0 :(得分:1)

我希望它能为您提供帮助:

 from("{{consumer.serviceName}}:queue:{{consumer.notificationQueue}}?{{consumer.queryParams}}").id("from_")
            .log(LoggingLevel.INFO, loggerObject, "Messages throttling from Queue")
            .throttle(constant("{{maximumRequestsPerSecond}}")).timePeriodMillis(1000)//pass throttle.timePeriod parameter from your config here
            .log(LoggingLevel.INFO, loggerObject, "Consuming notification message from Queue {{consumer.myQueue}} : ${body}")
            .bean(beanObject, "process").id("beanId")
            .end();