我需要让 Spring 应用程序每 X 分钟轮询一次给定的 URL,然后根据远程服务器返回的 HTTP 状态代码发布应用程序事件。我对一些特定的状态代码感兴趣:200(然后处理内容)、404(然后引发错误消息)和 301(然后不执行任何操作。)
我不想重新发明轮子,所以......
实现这一目标的最佳方法是什么?是否有任何现成可用的东西(例如在 spring-integration 中,但欢迎任何其他库)或者我必须自己编写它?
预先感谢您的帮助。
最佳答案
Spring Integration 是最好的选择。
这是一个示例集成路线:
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000"></int:poller>
</int:inbound-channel-adapter>
<int:channel id="quakeinfo.channel">
<int:queue capacity="10"/>
</int:channel>
<int:channel id="quakeinfotrigger.channel"></int:channel>
<int-http:outbound-gateway id="quakerHttpGateway"
request-channel="quakeinfotrigger.channel"
url="http://earthquake.usgs.gov/earthquakes/feed/geojson/all/hour"
http-method="GET"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="5000"
reply-channel="quakeinfo.channel">
</int-http:outbound-gateway>
完整来源要点:引用:Link
关于java - 使用 Spring 进行 http url 轮询的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340193/