gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:45:51 24 4
gpt4 key购买 nike

下面是我在 XML 中完美运行的 Camel 路线

<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编写一个类似的camel端点。您能告诉我如何在其中添加日志和节流属性吗?

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

最佳答案

希望对您有帮助:

 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();

关于java - Apache Camel - 如何在 java 中使用属性配置端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52587096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com