★ wanayoo — archive 1999 https://github.com/spring-cloud/spring-cloud-task/pull/697Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding KafkaItemWriter single step autoconfig #697

Open
wants to merge 3 commits into
base: master
from

Conversation

@cppwfs
Copy link
Contributor

@cppwfs cppwfs commented Aug 5, 2020 •

resolves #696
The base set of properties to setup are the following to activate the writer:

spring.batch.job.kafkaitemwriter.topic=<your topic name>
spring.kafka.consumer.bootstrap-servers=localhost:9092

If you want to have a serializer for the value or key that is different than the boot provided default StringSerializer you can set the following properties to the serializer needed. In the example below I use the JsonSerializer.

spring.kafka.producer.key-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer

If a user needs another itemKeyMapper besides the default provided you can create a new bean with the name beanItemNameMapper. i.e.

	@Bean(name = "batchItemKeyMapper")
	public Converter<Object, Object> batchItemKeyMapper()
@cppwfs cppwfs requested review from mminella and benas Aug 5, 2020
@cppwfs
Copy link
Contributor Author

@cppwfs cppwfs commented Aug 11, 2020

Autowire in ItemKeyMapper instead of null

@cppwfs cppwfs force-pushed the cppwfs:TASK-696 branch 2 times, most recently from a9d6716 to cbf83d0 Aug 11, 2020

private String topic;

private long pollTimeOutInSeconds = 30L;

This comment has been minimized.

@benas

benas Aug 14, 2020
Collaborator

This is not used on the writer side.

This comment has been minimized.

@cppwfs

cppwfs Aug 14, 2020
Author Contributor

EeekEEk, busted on copy paste :-)

@ConfigurationProperties(prefix = "spring.batch.job.kafkaitemwriter")
public class KafkaItemWriterProperties {

private String name;

This comment has been minimized.

@benas

benas Aug 14, 2020 •
Collaborator

A kafkaItemWriter does not have a name property (it is not an ItemStream), so this is not needed.

This comment has been minimized.

@cppwfs

cppwfs Aug 14, 2020
Author Contributor

We need the name to disable and enable auto configuration.

}

/**
* The topic name from which the messages will be read.

This comment has been minimized.

@benas

benas Aug 14, 2020
Collaborator

On the writer's side, this should be "The topic name to which messages will be written". Same thing for the getter's javadoc.

This comment has been minimized.

@cppwfs

cppwfs Aug 14, 2020
Author Contributor

EEk, busted on copy paste :-)

validateProperties(kafkaItemWriterProperties);
KafkaTemplate template = new KafkaTemplate(producerFactory);
template.setDefaultTopic(kafkaItemWriterProperties.getTopic());
return new KafkaItemWriterBuilder<Object, Map<Object, Object>>().delete(false)

This comment has been minimized.

@benas

benas Aug 14, 2020
Collaborator

Why is delete hard-coded to false here? I think it should be configurable in KafkaItemWriterProperties.

This comment has been minimized.

@cppwfs

cppwfs Aug 14, 2020
Author Contributor

DOH! I have a branch I haven't pushed up with that change.

return new Converter() {
@Override
public Object convert(Object source) {
return "";

This comment has been minimized.

@benas

benas Aug 14, 2020
Collaborator

This might be problematic if the key type is not a String. I would return the source object as a key without any modification. BTW, since the itemkeyMapper is mandatory, I would make the user provide it and fail fast if it's absent. Otherwise, this default mapper can be silently used with unintended side effects (in this case, it would be writing all items with an empty String as a key).

@cppwfs
Copy link
Contributor Author

@cppwfs cppwfs commented Aug 14, 2020

I also need to qualify the use of the Converter bean. Boot out of the box enables 3, so I need to qualify the one we want. A update is on the way.

cppwfs added 3 commits Aug 3, 2020
Set a very simple keymapper that returns the same result
@cppwfs cppwfs force-pushed the cppwfs:TASK-696 branch from 61611ee to 12736cb Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.