use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class QCloudBaseUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
// 填充请求参数
TreeMap<String, String> params = fillRequestArgs(msg);
// 生成签名
String sign = createSignature(params);
params.put("Signature", sign);
LOG.info(String.format("腾讯云API调用,请求参数:%s", JSON.toJSONString(params)));
try {
Request request = HttpKit.get("https://" + getAPIHost() + HHTP_APIURL);
for (Entry<String, String> param : params.entrySet()) {
request.addParam(param.getKey(), param.getValue());
}
request.setSSL(null, null);
String result = request.executeLocal().string();
return UnitResponse.success(convert(result));
} catch (ConnectException e) {
LOG.error("调用腾讯云API连接超时", e);
throw new RuntimeException("调用腾讯云API连接超时");
} catch (SocketTimeoutException e) {
LOG.error("调用腾讯云API响应超时", e);
throw new RuntimeException("调用腾讯云API响应超时");
} catch (Exception e) {
LOG.error("调用腾讯云API出错", e);
throw new RuntimeException("调用腾讯云API出错");
}
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class CacheMapRemoveUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.getArgMap().get("key").toString();
String field = msg.getArgMap().get("field").toString();
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
long length;
try {
length = Redis.call(cacheConfigBean, jedis -> jedis.hdel(key, field));
} catch (Exception e) {
return UnitResponse.exception(e);
}
return UnitResponse.success(length);
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class TransactionalCache method rollbackDistributedTrans.
public static void rollbackDistributedTrans() {
JSONArray clientIds = JSON.parseObject(transMetas.get(MsgIdHolder.get())).getJSONArray("clientIds");
if (clientIds != null && !clientIds.isEmpty()) {
String clientId = clientIds.getString(0);
UnitRequest request = UnitRequest.create(Constant.SYSTEM_DAO_GROUP_NAME, "rollbackAndCloseTogether");
request.getContext().setDestinationNodeId(clientId);
LocalNodeManager.send(request, new NotifyHandler() {
protected void handle(UnitResponse unitResponse) {
LOG.info(clientId + "的事务已经回滚");
}
});
} else {
LOG.warn("回滚事务时,缓存中的事务信息竟然是空的!", new RuntimeException());
}
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class TransactionalCache method commitDistributedTrans.
public static void commitDistributedTrans() {
decreaseCount();
JSONArray clientIds = JSON.parseObject(transMetas.get(MsgIdHolder.get())).getJSONArray("clientIds");
if (clientIds != null && !clientIds.isEmpty()) {
String clientId = clientIds.getString(0);
UnitRequest request = UnitRequest.create(Constant.SYSTEM_DAO_GROUP_NAME, "commitAndCloseTogether");
request.getContext().setDestinationNodeId(clientId);
LocalNodeManager.send(request, new NotifyHandler() {
protected void handle(UnitResponse unitResponse) {
LOG.info(clientId + "的事务已经提交");
}
});
} else {
LOG.warn("提交事务时,缓存中的事务信息竟然是空的!", new RuntimeException());
}
}
Aggregations