这是OpenHub框架系列文章的第三篇——第一篇介绍OpenHub框架,第二篇介绍异步消息模型。
本系列的最后一篇文章将更详细地介绍一些其他有趣的功能,并将说明 OpenHub 可以成为您的集成项目的理想选择的原因。
节流是一种检查集成平台输入请求计数的功能,如果此计数超过定义的限制,则新请求将受到限制。
节流的主要目标是限制集成平台不成比例的(通常是故意的)过载处理大量输入请求。这会对应用程序性能产生不良影响,甚至会停止当前消息的处理。
节流组件 计算来自指定源(外部)系统和特定操作的输入请求。如果此计数在定义的时间间隔内超过定义的限制,则 OpenHub 将开始拒绝新的输入请求(仅来自指定源系统和指定操作的请求)——抛出异常。节流组件支持集群。
节流功能可以配置如下:
############################################################################### # Throttling configuration # # There the following property names: # - throttling.defaultInterval: default time interval (in seconds) if not defined by system/operation # - throttling.defaultLimit: default limit if not defined by system/operation # - throttling.sourceSystem.operationName, where # - sourceSystem is specific source system or '*' if any system # (source system is case-insensitive value from trace header (ExternalSystemExtEnum)) # - operationName is specific operation name or '*' if any operation # # Property values (except for default values) have the following format: # limit [/interval] # # Examples: # throttling.crm.op1=10 # throttling.crm.*=10/40 # throttling.*.sendSms=60/30 ############################################################################### throttling.defaultInterval=60 throttling.defaultLimit=60 throttling.sourceSystem.*=300/60 throttling.*.syncHello=15/60 throttling.*.asyncHello=50/60
例如:
throttling.crm.op1=10(限制从 CRM 系统调用操作 op1 10 个请求,持续 60 秒)节流。 crm.*=10/40(限制从 CRM 系统调用任何操作 10 个请求,持续 40 秒)throttling.*.sendSms=60/30(限制从任何系统调用操作 sendSms 到 60 个请求,持续 30 秒)
Alerts 定义监视数据库数据的指标,如果任何指标超过其限制,则会激活警报并可以执行进一步的操作。
指标是可配置的——用于获取项目计数和检查限制的 SQL 查询。
警报示例(也有后续操作):
默认配置示例:
############################################################################### # Alerts configuration # # There the following property names: # - alerts.N.id: unique alert identification (if not defined then order number (=N) is used instead) # - alerts.N.limit: limit that must be exceeded to activate alert # - alerts.N.sql: SQL query that returns count of items for comparison with limit value # - [alerts.N.enabled]: if specified alert is enabled or disabled; enabled is by default # - [alerts.N.mail.subject]: notification (email, sms) subject; can be used Java Formatter placeholders (%s = alert ID) # - [alerts.N.mail.body]: notification (email, sms) body; can be used Java Formatter placeholders (%d = actual count, %d = limit) # ############################################################################### # checks if there is any waiting message that exceeds time limit for timeout alerts.900.id=WAITING_MSG_ALERT alerts.900.limit=0 alerts.900.sql=SELECT COUNT(*) FROM message WHERE state = 'WAITING_FOR_RES' AND last_update_timestamp < (current_timestamp - interval '3600 seconds')
注意:每个配置都可以通过 JMX 即时设置。
OpenHub 支持两种类型的计划作业:
OpenHub 框架为作业定义提供了自己的 API。
配置示例:
@OpenHubQuartzJob(name = "AsyncPostponedJob", executeTypeInCluster = JobExecuteTypeInCluster.NOT_CONCURRENT, simpleTriggers = @QuartzSimpleTrigger(repeatIntervalMillis = 30000)) public void invokePostponedJob() {}
@OpenHubQuartzJob(name = "MoreTriggerJob", executeTypeInCluster = JobExecuteTypeInCluster.CONCURRENT, cronTriggers = { @QuartzCronTrigger(cronExpression = "0 00 23 ? * *", name = "FirstTriggerForJob", group = "MoreTriggerGroup"), @QuartzCronTrigger(cronExpression = "0 00 10 ? * *", misfireInstruction = CronTriggerMisfireInstruction.FIRE_ONCE_NOW, name = "SecondTriggerForJob", group = "MoreTriggerGroup")}, simpleTriggers = { @QuartzSimpleTrigger(repeatIntervalMillis = 10000, repeatCount = 20, name = "ThirdTriggerForJob", group = "MoreTriggerGroup"), @QuartzSimpleTrigger(repeatIntervalProperty = ASYNCH_PARTLY_FAILED_REPEAT_TIME_SEC, intervalPropertyUnit = SimpleTriggerPropertyUnit.SECONDS, misfireInstruction = SimpleTriggerMisfireInstruction.FIRE_NOW, name = "FourthTriggerForJob", group = "MoreTriggerGroup") }) public void invokeJob() {}
请求/响应跟踪功能允许将路由之间的内部通信或与外部系统的通信保存到数据库中。之后,您可以直接进入数据库并浏览请求 和响应 表或查看管理控制台。
消息详细信息——请求/响应跟踪
Apache Camel 中有一个基本的错误处理,但 OpenHub 框架有自己的概念来处理错误:
错误目录
标签2: Java教程地址:https://www.cundage.com/article/jcg-openhub-framework-next-interesting-features.html