use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class SendMessageHookImpl method sendMessageAfter.
@Override
public void sendMessageAfter(SendMessageContext context) {
try {
if (context == null || context.getMessage() == null) {
return;
}
MQTraceContext mqTraceContext = (MQTraceContext) context.getMqTraceContext();
MQTraceBean traceBean = mqTraceContext.getTraceBeans().get(0);
if (traceBean != null && context.getSendResult() != null) {
traceBean.setQueueId(context.getMq().getQueueId());
traceBean.setMsgId(context.getSendResult().getMsgId());
traceBean.setOffset(context.getSendResult().getQueueOffset());
mqTraceContext.setSuccess(true);
mqTraceContext.setStatus(context.getSendResult().getSendStatus().toString());
} else {
if (context.getException() != null) {
String msg = context.getException().getMessage();
mqTraceContext.setErrorMsg(StringUtils.substring(msg, 0, msg.indexOf("\n")));
}
}
MQSendMessageTraceLog.sendMessageAfter(mqTraceContext);
} catch (PradarException e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class ConcurrentlyTraceInterceptor method doBefore.
@Override
public void doBefore(Advice advice) throws Throwable {
try {
MessageQueue messageQueue = getMessageQueue(advice.getTarget());
List<MessageExt> messageExts = getMessages(advice.getTarget());
String consumeGroup = getConsumeGroup(advice.getTarget());
if (messageExts == null || messageExts.isEmpty()) {
return;
}
ConsumeMessageContext consumeMessageContext = new ConsumeMessageContext();
consumeMessageContext.setConsumerGroup(consumeGroup);
consumeMessageContext.setMq(messageQueue);
consumeMessageContext.setMsgList(messageExts);
consumeMessageContext.setSuccess(false);
hook.consumeMessageBefore(consumeMessageContext);
contextThreadLocal.set(consumeMessageContext);
} catch (PradarException e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class ConsumerPollInterceptor method doWithSpringIntercept.
public void doWithSpringIntercept(Advice advice) {
try {
if (!PradarSwitcher.isClusterTestEnabled()) {
return;
}
if (advice.getReturnObj() == null) {
return;
}
ConsumerRecords consumerRecords = (ConsumerRecords) advice.getReturnObj();
if (consumerRecords.count() <= 0) {
return;
}
Iterator iterator = consumerRecords.iterator();
Object next = iterator.next();
if (!(next instanceof ConsumerRecord)) {
return;
}
ConsumerRecord record = (ConsumerRecord) next;
String topic = record.topic();
Pradar.setClusterTest(false);
boolean isClusterTest = Pradar.isClusterTestPrefix(topic);
if (PradarSwitcher.isKafkaMessageHeadersEnabled()) {
Headers headers = record.headers();
Header header = headers.lastHeader(PradarService.PRADAR_CLUSTER_TEST_KEY);
if (header != null) {
isClusterTest = isClusterTest || ClusterTestUtils.isClusterTestRequest(BytesUtils.toString(header.value()));
}
}
if (isClusterTest) {
Pradar.setClusterTest(true);
}
} catch (PradarException e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class PullConsumeMessageHookImpl method consumeMessageAfter.
@Override
public void consumeMessageAfter(ConsumeMessageContext context) {
try {
if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) {
return;
}
MQTraceContext mqTraceContext = (MQTraceContext) context.getMqTraceContext();
mqTraceContext.setSuccess(context.isSuccess());
mqTraceContext.setStatus(context.getStatus());
MQConsumeMessageTraceLog.consumeMessageAfter(mqTraceContext);
} catch (PradarException e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
LOGGER.error("", e);
if (Pradar.isClusterTest()) {
throw new PressureMeasureError(e);
}
}
}
use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.
the class BeforeTraceInterceptor method doException.
@Override
public final void doException(Advice advice) throws Throwable {
Object ctx = advice.attachment();
if (ctx == null) {
return;
}
if (popContextBefore()) {
return;
}
Object currentCtx = Pradar.getInvokeContext();
Throwable throwable;
try {
/**
* 如果出现异常则从 attachment中获取上下文,然后重建上下文
*/
Pradar.setInvokeContext(ctx);
advice.attach(null);
throwable = null;
try {
exceptionFirst(advice);
} catch (PradarException e) {
LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("TraceInterceptor exceptionFirst exec err:{}", this.getClass().getName(), t);
throwable = t;
}
try {
if (isClient(advice)) {
endClientInvokeException(advice);
} else {
endServerInvokeException(advice);
}
} catch (PradarException e) {
LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
if (Pradar.isClusterTest()) {
throw e;
}
} catch (Throwable e) {
if (Pradar.isClusterTest()) {
LOGGER.error("TraceInterceptor exception exec err:{}", this.getClass().getName(), e);
throw new PressureMeasureError(e);
}
} finally {
try {
exceptionLast(advice);
} catch (PradarException e) {
LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (PressureMeasureError e) {
LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), e);
throwable = e;
} catch (Throwable t) {
LOGGER.error("TraceInterceptor exceptionLast exec err:{}", this.getClass().getName(), t);
throwable = t;
}
}
} finally {
Pradar.setInvokeContext(currentCtx);
}
if (throwable != null && Pradar.isClusterTest()) {
throw throwable;
}
}
Aggregations