use of org.springframework.amqp.rabbit.annotation.RabbitHandler in project daijie-example by daijiejay.
the class ConsumerTest method process.
@RabbitHandler
@RabbitListener(queues = "hello")
public void process(Message message) {
byte[] body = message.getBody();
User user = (User) SerializeUtil.deserialize(body);
System.out.println(user.getUserName());
}
use of org.springframework.amqp.rabbit.annotation.RabbitHandler in project fw-cloud-framework by liuweijw.
the class LogRabbitListener method receive.
@RabbitHandler
public void receive(AuthLog authLog) {
Log sysLog = authLog.getLog();
MDC.put(CommonConstant.KEY_USER, authLog.getLog().getCreateBy());
Date currentDate = new Date();
if (null == sysLog.getCreateTime())
sysLog.setCreateTime(currentDate);
if (null == sysLog.getUpdateTime())
sysLog.setUpdateTime(currentDate);
LogInfo logInfo = new LogInfo();
BeanUtils.copyProperties(sysLog, logInfo);
logInfoService.saveOrUpdate(logInfo);
MDC.remove(CommonConstant.KEY_USER);
}
use of org.springframework.amqp.rabbit.annotation.RabbitHandler in project fw-cloud-framework by liuweijw.
the class NotifyRabbitListenter method receive.
@RabbitHandler
public void receive(NotifyBean notifyBean) {
if (null == notifyBean)
return;
String respUrl = notifyBean.getUrl();
if (StringHelper.isBlank(respUrl)) {
log.warn("notify url is empty. respUrl={}", respUrl);
return;
}
String orderId = notifyBean.getOrderId();
int count = null == notifyBean.getCount() ? 0 : notifyBean.getCount();
try {
log.info("==>MQ通知业务系统开始[orderId:{}][count:{}][time:{}]", orderId, count, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
restTemplate = HttpUtil.restTemplate(respUrl);
String resultResponse = restTemplate.postForObject(respUrl, HttpEntity.EMPTY, String.class);
log.info("==>MQ通知业务系统发生请求结果[{}]", resultResponse);
// 验证结果
log.info("notify response , OrderID={}", orderId);
if (resultResponse.equalsIgnoreCase(PayConstant.RETURN_VALUE_SUCCESS)) {
log.info("{} notify success, url:{}", notifyBean.getOrderId(), respUrl);
// 修改订单表
try {
boolean result = payOrderService.updatePayOrderStatus4Complete(orderId);
log.info("修改payOrderId={},订单状态为处理完成->{}", orderId, result ? "成功" : "失败");
} catch (Exception e) {
log.error("修改订单状态为处理完成异常" + e);
}
// 修改通知次数
try {
boolean result = payOrderService.updateNotify(orderId, 1);
log.info("修改payOrderId={},通知业务系统次数->{}", orderId, result ? "成功" : "失败");
} catch (Exception e) {
log.error("修改通知次数异常" + e);
}
// 通知成功结束
return;
} else {
// 通知失败,延时再通知
int cnt = count + 1;
log.info("notify count={}", cnt);
// 修改通知次数
try {
boolean result = payOrderService.updateNotify(orderId, cnt);
log.info("修改payOrderId={},通知业务系统次数->{}", orderId, result ? "成功" : "失败");
} catch (Exception e) {
log.error("修改通知次数异常" + e);
}
if (cnt > 5) {
log.info("notify count>5 stop. url={}", respUrl);
return;
}
notifyBean.setCount(cnt);
this.notifyService.notifyPayOrder(notifyBean, cnt * 60 * 1000);
}
log.warn("notify failed. url:{}, response body:{}", respUrl, resultResponse);
} catch (Exception e) {
log.info("<==MQ通知业务系统结束[orderId:{}][count:{}][time:{}]", orderId, count, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
log.error("notify exception. url:" + respUrl + "|exception:" + e);
}
}
use of org.springframework.amqp.rabbit.annotation.RabbitHandler in project fw-cloud-framework by liuweijw.
the class WechatRabbitListener method receive.
@RabbitHandler
public void receive(WechatNotifyBean wechatNotifyBean) {
long start = System.currentTimeMillis();
log.info("【wxauth.wechatRabbit】:exec receive start|" + start);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = wechatNotifyBean.getWxMpOAuth2AccessToken();
if (null == wxMpOAuth2AccessToken || StringHelper.isBlank(wechatNotifyBean.getWechatId()) || StringHelper.isBlank(wxMpOAuth2AccessToken.getOpenId()))
return;
log.info("【wxauth.wechatRabbit】:exec start");
try {
WxMpUser wxMpUser = null;
String openId = wxMpOAuth2AccessToken.getOpenId();
AuthInfo authInfo = authInfoService.findByOpenIdAndWechatId(openId, wechatNotifyBean.getWechatId());
if (// 大于2小时
null == authInfo || System.currentTimeMillis() - authInfo.getUpdateTime().getTime() > 7200000) {
boolean isSopeBase = wechatNotifyBean.isSopeBase();
if (isSopeBase) {
log.info("【wxauth.openId】静默登录");
wxMpUser = wxService.getUserService().userInfo(openId);
} else {
// refresh_token有效期为30天,当refresh_token失效之后,需要用户重新授权。
String refreshToken = wxMpOAuth2AccessToken.getRefreshToken();
wxMpOAuth2AccessToken = wxService.oauth2refreshAccessToken(refreshToken);
log.info("【wxauth.openId】主动登录");
// 拉取用户信息(需scope为 snsapi_userinfo)
wxMpUser = wxService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
}
if (null != wxMpUser) {
if (null == authInfo)
authInfo = new AuthInfo();
authInfo.setOpenId(openId);
authInfo.setWechatId(wechatNotifyBean.getWechatId());
authInfo.setNickName(WebUtils.buildURLEncoder(EmojiUtils.toHtml(wxMpUser.getNickname())));
authInfo.setHeadImgUrl(wxMpUser.getHeadImgUrl());
authInfo.setCity(wxMpUser.getCity());
authInfo.setProvince(wxMpUser.getProvince());
authInfo.setLanguage(wxMpUser.getLanguage());
authInfo.setRemark(wxMpUser.getRemark());
authInfo.setSexDesc(wxMpUser.getSexDesc());
authInfo.setSex(wxMpUser.getSex());
authInfo.setCountry(wxMpUser.getCountry());
authInfo.setRefreshToken(wxMpOAuth2AccessToken.getRefreshToken());
if (null == authInfo.getCreateTime())
authInfo.setCreateTime(new Date());
authInfo.setUpdateTime(new Date());
authInfoService.saveOrUpdate(authInfo);
}
}
log.info("【wxauth.wechatRabbit】:openId|" + openId);
} catch (WxErrorException ex) {
ex.printStackTrace();
log.info("【wxauth.wechatRabbit】exception:" + ex.getError().getErrorMsg());
}
log.info("【wxauth.wechatRabbit】:exec finished 耗时:" + (System.currentTimeMillis() - start));
}
Aggregations