如何在运行时使用 Camel 更改处理器属性? [英] How to change Processor properties during runtime using Camel?

查看:29
本文介绍了如何在运行时使用 Camel 更改处理器属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 Java DSL 编写的 Camel 路由定义,如下所示:

I have a Camel Route Definition written in Java DSL like this:

from(myEndpoint) 
.throttle(200)
.to(myOtherEndpoint);

这使用 Throttler 连接我的两个端点,将消息流限制为每秒 200 条消息.

This connects my two endpoints using a Throttler which limits the message flow to 200 messages per second.

我正在寻找一种在运行时更改最大请求计数/秒的方法.所以我需要以某种方式到达被调用的 Throttler 实例并更改属性.

I'm looking for a way to change the maximumRequestCount / second during runtime. So I need to somehow get to the Throttler instance which is called and change the property.

如何访问节流阀?

推荐答案

好吧,我自己想出来的......

Ok, I figured it out by myself ...

您需要自己定义 Throttler 实例.

You need to define your Throttler instance yourself.

Throttler throttler = new Throttler(null, 200);

然后你可以像这样在你的路由中使用它,因为 Throttler 实现了 Processor 接口:

Then you can use it in your routes like this, because Throttler implements the Processor interface:

from(myEndpoint) 
.process(throttler)
.to(myOtherEndpoint);

您可以随时更改节流器的属性.

Any time you like you can change the properties of the throttler.

这篇关于如何在运行时使用 Camel 更改处理器属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆