最佳实践

6.2 SmarttaxClient最佳范例

since v1.2.0.0

SmarttaxClient会随着您的应用自动启动并自己维护与远程服务的网络长连接,当网络环境不佳时,SmarttaxClient在请求远程服务失败时会抛出非受检异常(unchecked exception)net.smarttax.sim.exception.DropletClientException,您可以根据业务需要酌情处理。

   final String sampleSID = CommonUtils.buildUUID16();
    try{
      String sid = smarttaxClient.blanks(ReqDTO.build(sampleSID
                , taxCode, deviceCode, invoiceType));

      // do something when sending success.
        log.info("Droplet client successfully sends a message: [{}].",sid);

    }catch (DropletClientException dce){
        // do something when error occurs.
        log.error("Droplet client occurs an error while sending message: [{}].",dce.getMsg());
    }

    return sampleSID;
 ERROR 11604 --- [nio-7171-exec-3] net.smarttax.sdkdemo.MockController      : Droplet client occurs an error while sending message: [Droplet failed to send packet , SID-[600f3b6ab7f741] , cause: [Client has disconnected.]].
  • SmarttaxClient正常返回业务流水号后您可认为任务已被成功发送。
  • 反之,在捕获到net.smarttax.sim.exception.DropletClientException后,可在msg字段获取发送失败的具体原因(主要是网络环境错误)。

6.3 SmarttaxClient的可靠性

since v1.2.0.0

  • 离线推送机制: 在发生网络抖动等网络问题时,SmarttaxClient会自动尝试取得重新连接,哪怕是正在等待响应的过程中突然断线,远程服务会自动保存离线的SmarttaxClient的连接实例的业务操作结果,并在该账号重新取得连接后将离线期间的结果逐个推送。

  • 延迟推送机制: 对于耗时任务,如大批量的发票修复,本地环境不佳的开票任务等,你可能在发送任务后会先收到net.smarttax.sim.entity.enums.OperationStatus#PENDING的状态响应(3min之内),表示此时后台任务正在处理中,当任务处理完毕远程服务会自动推送最终结果至SmarttaxClient

results matching ""

    No results matching ""