OpenHub框架–下一个有趣的功能

这是有关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的调用限制为60秒内有10个请求)
throttling.crm。* = 10/40 (限制从CRM系统到40秒内10个请求的任何调用)
* .sendSms = 60/30 (限制从任何系统到30秒内60个请求的sendSms操作调用)

警报

警报定义用于监视数据库数据的度量标准,如果任何度量标准超出其限制,则会激活警报并可以执行进一步的操作。

度量是可配置的–用于获取项目计数和检查限制的SQL查询。

警报示例(还包括后续操作):

  • 当最近10分钟的失败消息计数超过5时,则向管理员发送电子邮件
  • 当等待外部系统响应超过5分钟的邮件数超过10时,则向管理员发送电子邮件

默认配置示例:

###############################################################################
#  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支持两种类型的计划作业

  1. 可以在随机节点上运行并可以同时执行的作业(没有条件同时启动作业
  2. 无论在哪个节点上,群集中只能运行一次的作业(请注意:我们没有考虑计划的作业只能在特定节点上运行的可能性)

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框架有其自己的概念来处理错误:

  • 有自己的带有基本IntegrationException的异常层次结构
  • 错误目录定义了带有描述的唯一错误代码–这有助于识别源系统中的问题
  • 错误目录显示在管理控制台中
错误目录

错误目录


翻译自: https://www.javacodegeeks.com/2017/11/openhub-framework-next-interesting-features.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值