package de.juplo.kafka;
import org.apache.kafka.clients.producer.KafkaProducer;
+import org.apache.kafka.common.serialization.IntegerSerializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.support.serializer.JsonSerializer;
import java.util.Properties;
props.put("linger.ms", properties.getLingerMs());
props.put("compression.type", properties.getCompressionType());
props.put("key.serializer", StringSerializer.class.getName());
- props.put("value.serializer", JsonSerializer.class.getName());
- props.put(JsonSerializer.TYPE_MAPPINGS,
- "ADD:" + AddNumberMessage.class.getName() + "," +
- "CALC:" + CalculateSumMessage.class.getName());
+ props.put("value.serializer", IntegerSerializer.class.getName());
return new KafkaProducer<>(props);
}
@RequestHeader(name = "X-id", required = false) Long correlationId,
@RequestBody Integer number)
{
- ResultRecorder result = new ResultRecorder(number+1);
+ ResultRecorder result = new ResultRecorder(1);
- for (int i = 1; i <= number; i++)
- {
- send(key, new AddNumberMessage(number, i), correlationId, result);
- }
- send(key, new CalculateSumMessage(number), correlationId, result);
+ send(key, number, correlationId, result);
return result.getDeferredResult();
}
.andExpect(status().isOk());
await("Message was send")
.atMost(Duration.ofSeconds(5))
- .until(() -> consumer.received.size() == 667);
+ .until(() -> consumer.received.size() == 1);
}