|
|
package com.yohoufo.order.mq.consumer;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.ServiceException;
|
|
|
import com.yoho.core.rabbitmq.YhConsumer;
|
|
|
import com.yohoufo.common.alarm.EventBusPublisher;
|
|
|
import com.yohoufo.common.alarm.SmsAlarmEvent;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
|
...
|
...
|
@@ -30,19 +33,37 @@ public abstract class JsonObjectMessageConsumer<M> implements YhConsumer { |
|
|
messageClass = (Class) params[0];
|
|
|
}
|
|
|
|
|
|
|
|
|
public abstract String getTopic();
|
|
|
|
|
|
public abstract void handle(M message);
|
|
|
|
|
|
@Override
|
|
|
public void handleMessage(Object o) throws Exception {
|
|
|
public void handleMessage(Object jsonText) throws Exception {
|
|
|
String topic = getTopic();
|
|
|
M message;
|
|
|
logger.info("in topic {}, msg {}", topic, jsonText);
|
|
|
try {
|
|
|
message = JSONObject.parseObject(o.toString(), messageClass);
|
|
|
message = JSONObject.parseObject(jsonText.toString(), messageClass);
|
|
|
} catch (Exception e) {
|
|
|
getLogger().warn("parse message {} fail", o, e);
|
|
|
getLogger().warn("parse message fail, topic {}, msg {}", topic, jsonText, e);
|
|
|
return;
|
|
|
}
|
|
|
handle(message);
|
|
|
try {
|
|
|
handle(message);
|
|
|
} catch (ServiceException e) {
|
|
|
getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e);
|
|
|
} catch (Exception e) {
|
|
|
getLogger().warn("handler message fail, topic {}, msg {}", topic, jsonText, e);
|
|
|
SmsAlarmEvent smsAlarmEvent = new SmsAlarmEvent(
|
|
|
topic,
|
|
|
"ufo_mq_consumer_exception",
|
|
|
e.toString()
|
|
|
);
|
|
|
EventBusPublisher.publishEvent(smsAlarmEvent);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public abstract void handle(M message);
|
|
|
|
|
|
public Logger getLogger() {
|
|
|
return logger;
|
...
|
...
|
|