定时推送任务
需求
需要定时推送我方的数据到对方那边
方法1 Apache HttpClient
此方法指定推送过去的信息转为utf-8格式的json字符串
@Scheduled(initialDelay = 1000 * 120, fixedDelay = 1000 * 60 * 5)
public void diseaseInterface() {
String lockKey = "lock:diseaseInterface";
String requestId = UUID.randomUUID().toString();
boolean acquired = false;
try {
// 加锁,锁定时间为15分钟
acquired = redisTemplate.opsForValue().setIfAbsent(lockKey, requestId, Duration.ofMinutes(15L));
if (acquired) {
MainBody mainBody = interfaceService.diseaseInterface(new WebServiceBO());
if (mainBody != null) {
String sendUrl = "对方的接口";
// 如果在数据库中配置了接口信息,就从数据库中查询并赋值
Code code = codeService.selectByPrimaryKey(DATABASE_CODE_PK_JXZ);
if (code != null && StringUtils.isNotEmpty(code.getCode())) {
sendUrl = code.getCode();
}
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(sendUrl);
StringEntity entity = new StringEntity(JSON.toJSONString(mainBody), "utf-8")

最低0.47元/天 解锁文章
1186

被折叠的 条评论
为什么被折叠?



