Search in sources :

Example 1 with ThroughputThrottler

use of org.apache.kafka.tools.ThroughputThrottler in project kafka by apache.

the class VerifiableSourceTask method start.

@Override
public void start(Map<String, String> props) {
    final long throughput;
    try {
        name = props.get(NAME_CONFIG);
        id = Integer.parseInt(props.get(ID_CONFIG));
        topic = props.get(TOPIC_CONFIG);
        throughput = Long.parseLong(props.get(THROUGHPUT_CONFIG));
    } catch (NumberFormatException e) {
        throw new ConnectException("Invalid VerifiableSourceTask configuration", e);
    }
    partition = Collections.singletonMap(ID_FIELD, id);
    Map<String, Object> previousOffset = this.context.offsetStorageReader().offset(partition);
    if (previousOffset != null)
        seqno = (Long) previousOffset.get(SEQNO_FIELD) + 1;
    else
        seqno = 0;
    startingSeqno = seqno;
    throttler = new ThroughputThrottler(throughput, System.currentTimeMillis());
    log.info("Started VerifiableSourceTask {}-{} producing to topic {} resuming from seqno {}", name, id, topic, startingSeqno);
}
Also used : ThroughputThrottler(org.apache.kafka.tools.ThroughputThrottler) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Example 2 with ThroughputThrottler

use of org.apache.kafka.tools.ThroughputThrottler in project kafka by apache.

the class SchemaSourceTask method start.

@Override
public void start(Map<String, String> props) {
    final long throughput;
    try {
        name = props.get(NAME_CONFIG);
        id = Integer.parseInt(props.get(ID_CONFIG));
        topic = props.get(TOPIC_CONFIG);
        maxNumMsgs = Long.parseLong(props.get(NUM_MSGS_CONFIG));
        multipleSchema = Boolean.parseBoolean(props.get(MULTIPLE_SCHEMA_CONFIG));
        partitionCount = Integer.parseInt(props.containsKey(PARTITION_COUNT_CONFIG) ? props.get(PARTITION_COUNT_CONFIG) : "1");
        throughput = Long.parseLong(props.get(THROUGHPUT_CONFIG));
    } catch (NumberFormatException e) {
        throw new ConnectException("Invalid SchemaSourceTask configuration", e);
    }
    throttler = new ThroughputThrottler(throughput, System.currentTimeMillis());
    partition = Collections.singletonMap(ID_FIELD, id);
    Map<String, Object> previousOffset = this.context.offsetStorageReader().offset(partition);
    if (previousOffset != null) {
        seqno = (Long) previousOffset.get(SEQNO_FIELD) + 1;
    } else {
        seqno = 0;
    }
    startingSeqno = seqno;
    count = 0;
    log.info("Started SchemaSourceTask {}-{} producing to topic {} resuming from seqno {}", name, id, topic, startingSeqno);
}
Also used : ThroughputThrottler(org.apache.kafka.tools.ThroughputThrottler) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

ConnectException (org.apache.kafka.connect.errors.ConnectException)2 ThroughputThrottler (org.apache.kafka.tools.ThroughputThrottler)2