|
|
@ -17,11 +17,13 @@ package org.thingsboard.server.service.queue; |
|
|
|
|
|
|
|
|
import io.micrometer.core.instrument.Timer; |
|
|
import io.micrometer.core.instrument.Timer; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.thingsboard.server.common.data.exception.ApiUsageLimitsExceededException; |
|
|
import org.thingsboard.server.common.data.id.RuleNodeId; |
|
|
import org.thingsboard.server.common.data.id.RuleNodeId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.msg.queue.RuleEngineException; |
|
|
import org.thingsboard.server.common.msg.queue.RuleEngineException; |
|
|
import org.thingsboard.server.common.msg.queue.RuleNodeInfo; |
|
|
import org.thingsboard.server.common.msg.queue.RuleNodeInfo; |
|
|
import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
|
|
import org.thingsboard.server.common.msg.queue.TbMsgCallback; |
|
|
|
|
|
import org.thingsboard.server.common.msg.tools.TbRateLimitsException; |
|
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
@ -57,8 +59,24 @@ public class TbMsgPackCallback implements TbMsgCallback { |
|
|
ctx.onSuccess(id); |
|
|
ctx.onSuccess(id); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onRateLimit(RuleEngineException e) { |
|
|
|
|
|
log.debug("[{}] ON RATE LIMIT", id, e); |
|
|
|
|
|
//TODO notify tenant on rate limit
|
|
|
|
|
|
if (failedMsgTimer != null) { |
|
|
|
|
|
failedMsgTimer.record(System.currentTimeMillis() - startMsgProcessing, TimeUnit.MILLISECONDS); |
|
|
|
|
|
} |
|
|
|
|
|
ctx.onSuccess(id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onFailure(RuleEngineException e) { |
|
|
public void onFailure(RuleEngineException e) { |
|
|
|
|
|
Throwable cause = e.getCause(); |
|
|
|
|
|
if (cause instanceof TbRateLimitsException || cause instanceof ApiUsageLimitsExceededException) { |
|
|
|
|
|
onRateLimit(e); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
log.trace("[{}] ON FAILURE", id, e); |
|
|
log.trace("[{}] ON FAILURE", id, e); |
|
|
if (failedMsgTimer != null) { |
|
|
if (failedMsgTimer != null) { |
|
|
failedMsgTimer.record(System.currentTimeMillis() - startMsgProcessing, TimeUnit.MILLISECONDS); |
|
|
failedMsgTimer.record(System.currentTimeMillis() - startMsgProcessing, TimeUnit.MILLISECONDS); |
|
|
|