org.apache.kafka.streams.errors.LogAndContinueExceptionHandler Java Examples

The following examples show how to use org.apache.kafka.streams.errors.LogAndContinueExceptionHandler. 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: TestObjectMother.java    From adaptive-alerting with Apache License 2.0 6 votes vote down vote up
public static TopologyTestDriver topologyTestDriver(
        Topology topology,
        Class<?> valueSerdeClass,
        boolean continueOnDeserException) {

    val props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "test");
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, valueSerdeClass.getName());

    if (continueOnDeserException) {
        props.put(
                StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG,
                LogAndContinueExceptionHandler.class.getName());
    }

    return new TopologyTestDriver(topology, props);
}
 
Example #2
Source File: KafkaUtils.java    From SkaETL with Apache License 2.0 5 votes vote down vote up
public static Properties createKStreamProperties(String nameProcess, String bootstrapServers) {
    Properties props = new Properties();
    props.put(StreamsConfig.APPLICATION_ID_CONFIG, "application-process" + nameProcess);
    props.put(StreamsConfig.CLIENT_ID_CONFIG, nameProcess);
    props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
    props.put(StreamsConfig.COMMIT_INTERVAL_MS_CONFIG, 100);
    props.put(StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG, 0);
    props.put(StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, WallclockTimestampExtractor.class);
    props.put(StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG, LogAndContinueExceptionHandler.class.getName());
    return props;
}
 
Example #3
Source File: KafkaStreamsBinderSupportAutoConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@Bean("streamConfigGlobalProperties")
public Map<String, Object> streamConfigGlobalProperties(
		@Qualifier("binderConfigurationProperties") KafkaStreamsBinderConfigurationProperties configProperties,
		KafkaStreamsConfiguration kafkaStreamsConfiguration, ConfigurableEnvironment environment,
		SendToDlqAndContinue sendToDlqAndContinue) {

	Properties properties = kafkaStreamsConfiguration.asProperties();

	String kafkaConnectionString = configProperties.getKafkaConnectionString();

	if (kafkaConnectionString != null && kafkaConnectionString.equals("localhost:9092")) {
		//Making sure that the application indeed set a property.
		String kafkaStreamsBinderBroker = environment.getProperty("spring.cloud.stream.kafka.streams.binder.brokers");

		if (StringUtils.isEmpty(kafkaStreamsBinderBroker)) {
			//Kafka Streams binder specific property for brokers is not set by the application.
			//See if there is one configured at the kafka binder level.
			String kafkaBinderBroker = environment.getProperty("spring.cloud.stream.kafka.binder.brokers");
			if (!StringUtils.isEmpty(kafkaBinderBroker)) {
				kafkaConnectionString = kafkaBinderBroker;
				configProperties.setBrokers(kafkaConnectionString);
			}
		}
	}

	if (ObjectUtils.isEmpty(properties.get(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG))) {
		properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG,
				kafkaConnectionString);
	}
	else {
		Object bootstrapServerConfig = properties
				.get(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG);
		if (bootstrapServerConfig instanceof String) {
			@SuppressWarnings("unchecked")
			String bootStrapServers = (String) properties
					.get(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG);
			if (bootStrapServers.equals("localhost:9092")) {
				properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG,
						kafkaConnectionString);
			}
		}
		else if (bootstrapServerConfig instanceof List) {
			List bootStrapCollection = (List) bootstrapServerConfig;
			if (bootStrapCollection.size() == 1 && bootStrapCollection.get(0).equals("localhost:9092")) {
				properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG,
						kafkaConnectionString);
			}
		}
	}

	String binderProvidedApplicationId = configProperties.getApplicationId();
	if (StringUtils.hasText(binderProvidedApplicationId)) {
		properties.put(StreamsConfig.APPLICATION_ID_CONFIG,
				binderProvidedApplicationId);
	}

	properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG,
			Serdes.ByteArraySerde.class.getName());
	properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG,
			Serdes.ByteArraySerde.class.getName());

	if (configProperties
			.getDeserializationExceptionHandler() == DeserializationExceptionHandler.logAndContinue) {
		properties.put(
				StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG,
				LogAndContinueExceptionHandler.class);
	}
	else if (configProperties
			.getDeserializationExceptionHandler() == DeserializationExceptionHandler.logAndFail) {
		properties.put(
				StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG,
				LogAndFailExceptionHandler.class);
	}
	else if (configProperties
			.getDeserializationExceptionHandler() == DeserializationExceptionHandler.sendToDlq) {
		properties.put(
				StreamsConfig.DEFAULT_DESERIALIZATION_EXCEPTION_HANDLER_CLASS_CONFIG,
				RecoveringDeserializationExceptionHandler.class);
		properties.put(RecoveringDeserializationExceptionHandler.KSTREAM_DESERIALIZATION_RECOVERER, sendToDlqAndContinue);
	}

	if (!ObjectUtils.isEmpty(configProperties.getConfiguration())) {
		properties.putAll(configProperties.getConfiguration());
	}
	return properties.entrySet().stream().collect(
			Collectors.toMap((e) -> String.valueOf(e.getKey()), Map.Entry::getValue));
}