当前位置: 首页 > news >正文

怎样做网站全屏代码广州越秀区租房信息网

怎样做网站全屏代码,广州越秀区租房信息网,php做网站框架,网站制作软件名字线做1.引言 有时在调用Web服务时#xff0c;我们可能有兴趣在发生错误的情况下重试该操作。 使用Spring Integration时#xff0c;我们可以使用RequestHandlerRetryAdvice类实现此功能。 此类将使我们在放弃并引发异常之前重试指定次数的操作。 这篇文章将向您展示如何完成此任务… 1.引言 有时在调用Web服务时我们可能有兴趣在发生错误的情况下重试该操作。 使用Spring Integration时我们可以使用RequestHandlerRetryAdvice类实现此功能。 此类将使我们在放弃并引发异常之前重试指定次数的操作。 这篇文章将向您展示如何完成此任务。 测试应用程序将调用Web服务如果响应失败它将等待指定的时间然后重试直到收到响应或达到重试限制为止。 如果达到限制失败的请求将被存储到数据库中。 主要这篇文章显示以下示例 使用出站网关调用Web服务 配置重试建议以在必要时重试该操作 MongoDB集成。 该应用程序的源代码可以在github上找到。 您还可以在github上获取由应用程序调用的Web服务项目的源代码。 2.Web服务调用 用例 客户端调用Web服务并接收响应。 该请求通过“系统入口”网关进入消息传递系统。 然后它到达出站网关调用Web服务并等待响应。 收到响应后将其发送到响应通道。 上图是此配置的结果 context:component-scan base-packagexpadro.spring.integration /!-- Initial service request -- int:gateway idsystemEntry default-request-channelrequestChannelservice-interfacexpadro.spring.integration.gateway.ClientService /int:channel idrequestChannelint:queue / /int:channelint-ws:outbound-gateway idmarshallingGatewayrequest-channelrequestChannel reply-channelresponseChannelurihttp://localhost:8080/spring-ws/orders marshallermarshallerunmarshallermarshallerint:poller fixed-rate500 / /int-ws:outbound-gatewayoxm:jaxb2-marshaller idmarshaller contextPathxpadro.spring.integration.types /!-- Service is running - Response received -- int:channel idresponseChannel /int:service-activator refclientServiceActivator methodhandleServiceResult input-channelresponseChannel / 映射到响应通道的是一个服务激活器它仅记录结果。 TestInvocation.java将请求发送到入口网关 ContextConfiguration({classpath:xpadro/spring/integration/config/int-config.xml,classpath:xpadro/spring/integration/config/mongodb-config.xml}) RunWith(SpringJUnit4ClassRunner.class) public class TestInvocation {private Logger logger LoggerFactory.getLogger(this.getClass());Autowiredprivate ClientService service;Testpublic void testInvocation() throws InterruptedException, ExecutionException {logger.info(Initiating service request...);ClientDataRequest request new ClientDataRequest();request.setClientId(123);request.setProductId(XA-55);request.setQuantity(new BigInteger(5));service.invoke(request);logger.info(Doing other stuff...);Thread.sleep(60000);} } 使用此配置如果服务调用失败则将引发MessagingException并将其发送到错误通道。 在下一节中我们将添加重试配置。 3.添加重试建议 用例 初始请求失败因为该服务未激活。 我们将重试该操作直到从服务收到响应为止。 在这种情况下我们需要将重试建议添加到Web服务出站网关 int-ws:outbound-gateway idmarshallingGateway interceptorclientInterceptorrequest-channelrequestChannel reply-channelresponseChannelurihttp://localhost:8080/spring-ws/orders marshallermarshallerunmarshallermarshallerint:poller fixed-rate500 /int-ws:request-handler-advice-chainref beanretryAdvice //int-ws:request-handler-advice-chain /int-ws:outbound-gateway 现在Web服务出站网关会将调用委派给重试建议重试建议将按指定的次数尝试操作多次直到从服务获得响应为止。 让我们定义重试建议 bean idretryAdvice classorg.springframework.integration.handler.advice.RequestHandlerRetryAdvice property nameretryTemplatebean classorg.springframework.retry.support.RetryTemplateproperty namebackOffPolicybean classorg.springframework.retry.backoff.FixedBackOffPolicyproperty namebackOffPeriod value4000 //bean/propertyproperty nameretryPolicybean classorg.springframework.retry.policy.SimpleRetryPolicyproperty namemaxAttempts value4 //bean/property/bean/property /bean 为了实现其目标建议使用RetryTemplate该模板由Spring Retry项目提供。 我们可以通过定义退避和重试策略来自定义其行为。 退避政策 在每次重试之间建立一段时间。 更有趣的类型是 FixedBackOffPolicy 在我们的示例中使用。 每次重试之间将等待相同的指定时间。 ExponentialBackOffPolicy 从确定的时间量开始它将使每次重试的时间加倍。 您可以通过建立乘数来更改默认行为。 重试策略 确定将重试失败操作的次数。 一些类型 SimpleRetryPolicy 在我们的示例中使用。 指定重试次数限制。 ExceptionClassifierRetryPolicy 允许我们根据引发的异常来建立不同的maxAttempts。 TimeoutRetryPolicy 将继续重试直到达到超时为止。 4不走运记录失败的请求 用例 服务将无法恢复无法将请求存储到数据库中。 配置的最后部分如下 !-- Log failed invocation -- int:service-activator refclientServiceActivator methodhandleFailedInvocation input-channelerrorChannel output-channellogChannel /int:channel idlogChannel /bean idmongoDbFactory classorg.springframework.data.mongodb.core.SimpleMongoDbFactoryconstructor-argbean classcom.mongodb.Mongo//constructor-argconstructor-arg valuetest/ /beanint-mongodb:outbound-channel-adapter idmongodbAdapter channellogChannelcollection-namefailedRequests mongodb-factorymongoDbFactory / 订阅错误通道的服务激活器将检索失败的消息并将其发送到出站适配器出站适配器会将其插入到mongoDB数据库中。 服务激活器 public Message? handleFailedInvocation(MessagingException exception) {logger.info(Failed to succesfully invoke service. Logging to DB...);return exception.getFailedMessage(); } 如果我们未能成功从服务获得响应则该请求将存储到数据库中 六结论 我们已经了解了Spring Integration如何从Spring Retry项目获得支持以实现操作的重试。 我们使用了int-wsrequest-handler-advice-chain 但是int命名空间也支持此元素以将该功能添加到其他类型的端点。 参考在XavierPadró的Blog博客上我们的JCG合作伙伴 Xavier Padro 使用RequestHandlerRetryAdvice重试了Web服务操作 。 翻译自: https://www.javacodegeeks.com/2014/02/retry-web-service-operations-with-requesthandlerretryadvice.html
http://wiki.neutronadmin.com/news/332465/

相关文章:

  • 河北省企业网站建设公司青岛网站建设首选营销吧系统
  • 金华网站建设网站西凤酒网站建设
  • 返利网站建设服务thinkphp网站开发服务器
  • 枣庄网站制作公司搭建网站大概多少钱
  • 泉州企业建站模板扁平化网站模板下载
  • 杞县网站建设常州城投建设招标网站
  • 衡水微网站制作怎么做苏州手机网站建设费用
  • 电脑 手机 微信网站开发专业移动网站建设商
  • 东莞微网站制作h5网站怎么做的
  • 青岛开办公司要做网站吗有那个网站可以做报名链接的
  • 代刷网站推广链接0元价格攸县网站定制
  • 承德网站制作公司网络设计基本原则
  • 怎么为自己的厂做网站设计培训it培训
  • 网上下载的网站模板怎么用做公众号一般在哪个网站照片
  • 南宁企业网站制作哪家好wordpress文档chm
  • 门户网站开发过程视频网站域名登录不了
  • 上海微信小程序网站建设郑州直播app开发
  • title 网站建设公司实力建设银行网站怎么打印明细
  • 网站首次备案 多久怎样自己做淘宝客网站
  • 学院网站建设报告阿里云服务器发布网站
  • 做网站用什么天津网站优化流程
  • 销售型网站怎么做的免费网站推广群发软件
  • 做手机网站一般要多少钱网站数据泄露我们应该怎么做
  • 网站的网络营销方案seo 优化 服务
  • 做a动漫视频在线观看网站潍坊住房和城乡建设局招标网站
  • 邯郸网站设计哪家好北京做兼职从哪个网站好
  • 自己创建网站赚钱千万不要去代理记账公司上班
  • 上海商业网站建设费用十大品牌
  • 安徽网站推广系统wordpress作作品集
  • 网站页尾信息高德地图怎么看邮编