Search in sources :

Example 1 with ConsumerProxy

use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.

the class AbstractProxiedConsumerInterceptor method cutoff0.

@Override
public CutOffResult cutoff0(Advice advice) throws Throwable {
    ConsumerProxy consumerProxy = ConsumerHolder.getProxy(advice.getTarget());
    if (consumerProxy == null) {
        return CutOffResult.passed();
    }
    Object result = doCutoff(consumerProxy, advice);
    if (result instanceof CutOffResult) {
        return (CutOffResult) result;
    } else {
        return CutOffResult.cutoff(result);
    }
}
Also used : CutOffResult(com.pamirs.pradar.CutOffResult) ConsumerProxy(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy)

Example 2 with ConsumerProxy

use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.

the class ConsumerPollInterceptor method doOriginIntercept.

private CutOffResult doOriginIntercept(Advice advice) {
    if (GlobalConfig.getInstance().getMqWhiteList() == null || GlobalConfig.getInstance().getMqWhiteList().isEmpty()) {
        return CutOffResult.PASSED;
    }
    KafkaConsumer consumer = (KafkaConsumer) advice.getTarget();
    ConsumerMetaData consumerMetaData = ConsumerHolder.getConsumerMetaData(consumer);
    if (consumerMetaData == null) {
        return CutOffResult.passed();
    }
    Object[] args = advice.getParameterArray();
    long timeout = 100L;
    if (args[0] instanceof Long) {
        timeout = (Long) args[0];
    } else /* else if (args[0] instanceof Duration) {
                timeout = ((Duration)args[0]).toMillis();
            } */
    if (args[0] instanceof Timer) {
        timeout = ((Timer) args[0]).remainingMs();
    }
    if (consumerMetaData.isHasShadow()) {
        ConsumerProxy consumerProxy = ConsumerHolder.getProxyOrCreate(consumer, timeout);
        if (consumerProxy == null) {
            return CutOffResult.PASSED;
        }
        return CutOffResult.cutoff(consumerProxy.poll(timeout));
    } else {
        if (warnAlready.compareAndSet(false, true)) {
            LOGGER.warn("consumer with group id : {} topic : {} doesn't has shadow consumer config", consumerMetaData.getGroupId(), consumerMetaData.getTopics());
        }
        return CutOffResult.passed();
    }
}
Also used : ConsumerMetaData(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerMetaData) Timer(org.apache.kafka.common.utils.Timer) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) ConsumerProxy(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy)

Example 3 with ConsumerProxy

use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.

the class ShadowConsumerDisableListenerImpl method disableBatchOriginKafka.

private void disableBatchOriginKafka(String key, String topic, String group) {
    try {
        int code = ConsumerHolder.getShadowProxyMapping().get(key);
        ConsumerProxy consumerProxy = ConsumerHolder.getProxyMapping().get(code);
        consumerProxy.closePtConsumer();
        ConsumerHolder.getProxyMapping().remove(code);
        ConsumerHolder.getCache().remove(code);
        for (Map.Entry<Integer, ConsumerMetaData> entry : ConsumerHolder.getCache().entrySet()) {
            if (entry.getValue().getTopics().contains(Pradar.addClusterTestPrefix(topic)) && entry.getValue().getGroupId().equals(Pradar.addClusterTestPrefix(group))) {
                ConsumerHolder.getCache().remove(entry.getKey());
                break;
            }
        }
        ConsumerHolder.getShadowProxyMapping().remove(key);
    } catch (Throwable t) {
        logger.error("[apache-kafka]: {}", Throwables.getStackTraceAsString(t));
    }
}
Also used : ConsumerMetaData(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerMetaData) ConsumerProxy(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy) Map(java.util.Map)

Example 4 with ConsumerProxy

use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.

the class ShadowConsumerDisableListenerImpl method disableAllOriginKafka.

private void disableAllOriginKafka() {
    for (ConsumerProxy consumerProxy : ConsumerHolder.getProxyMapping().values()) {
        consumerProxy.closePtConsumer();
    }
    ConsumerHolder.getProxyMapping().clear();
    ConsumerHolder.getCache().clear();
    ConsumerHolder.getShadowProxyMapping().clear();
}
Also used : ConsumerProxy(com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy)

Aggregations

ConsumerProxy (com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy)4 ConsumerMetaData (com.pamirs.attach.plugin.apache.kafka.origin.ConsumerMetaData)2 CutOffResult (com.pamirs.pradar.CutOffResult)1 Map (java.util.Map)1 KafkaConsumer (org.apache.kafka.clients.consumer.KafkaConsumer)1 Timer (org.apache.kafka.common.utils.Timer)1