org.apache.kafka.common.errors.InvalidTopicException Java Examples

The following examples show how to use org.apache.kafka.common.errors.InvalidTopicException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KafkaValidator.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private static void validateTopic(final String topic, final DittoHeaders dittoHeaders,
        final String placeholderReplacement) {

    if (topic.isEmpty()) {
        throwEmptyException("topic", dittoHeaders);
    }

    try {
        final String topicWithoutPlaceholders =
                topic.replaceAll(Pattern.quote(placeholderReplacement), DUMMY_TOPIC);
        Topic.validate(topicWithoutPlaceholders);
    } catch (final InvalidTopicException e) {
        final String message = MessageFormat.format(INVALID_TOPIC_FORMAT, topic, e.getMessage());
        throw ConnectionConfigurationInvalidException.newBuilder(message)
                .dittoHeaders(dittoHeaders)
                .cause(e)
                .build();
    }
}
 
Example #2
Source File: KafkaPublishTarget.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private static String validateTopic(final String topic) {
    try {
        Topic.validate(topic);
        return topic;
    } catch (final InvalidTopicException e) {
        throw ConnectionConfigurationInvalidException.newBuilder(e.getMessage())
                .cause(e)
                .build();
    }
}
 
Example #3
Source File: KafkaAdminClientTest.java    From common-kafka with Apache License 2.0 4 votes vote down vote up
@Test(expected = InvalidTopicException.class)
public void createTopic_invalidTopicName() {
    client.createTopic("I'm not a valid topic!", 1, 1);
}
 
Example #4
Source File: OddEvenPartitioner.java    From Kafka-Streams-Real-time-Stream-Processing with The Unlicense 3 votes vote down vote up
/**
 * Simple partitioning on the message key
 * Odd keys to partition 0
 * Even keys to partition 1
 *
 * @param topic topic Name
 * @param key Message Key
 * @param keyBytes Key Bytes
 * @param value Message Value
 * @param valueBytes Value Bytes
 * @param cluster Cluster Object
 * @return Partition Id
 */
@Override
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
    if ((keyBytes == null) || (!(key instanceof Integer)))
        throw new InvalidRecordException("Topic Key must have a valid Integer value.");

    if (cluster.partitionsForTopic(topic).size() != 2)
        throw new InvalidTopicException("Topic must have exactly two partitions");

    return (Integer) key % 2;
}