【问题标题】:Best way to test application services from outside the application从应用程序外部测试应用程序服务的最佳方式
【发布时间】:2011-09-10 23:23:43
【问题描述】:
我有一个 spring 应用程序,它使用 MySQL、PostgreSQL 和 Bing 的位置 Web 服务等多种服务。它们都工作正常,我进行了一些单元和集成测试以确保它们正常工作。
昨天有人要求我为每个服务创建 keepalive 页面,以告知该服务是否可用,以便我的系统管理员可以从 nginx 调用这些页面。
我知道我可以创建一个带有验证每个服务的方法的新控制器,但这是最好的方法吗?我认为他会想要经常进行这些检查。如果有人对更多信息有任何建议或链接,我将不胜感激。
谢谢
【问题讨论】:
标签:
java
spring
nginx
keep-alive
【解决方案1】:
我会为此走一条不同的路线,您可以像这样创建一个弹簧服务
@Component
public class MonitorService
{
public void checkServices()
{
//if(problem) send an e-mail notification,
//you can configure spring MailSender to do that
}
}
现在您创建一个 spring 任务调度程序以固定间隔运行此监视器
<task:scheduled-tasks>
<task:scheduled ref="monitorService" method="checkServices" fixed-delay="1000"/>
</task:scheduled-tasks>