import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.ListenableFuture;
-import java.util.List;
@Slf4j
@SpringBootApplication
public class Application implements ApplicationRunner
{
- public final static String ARG_NUM = "num";
-
@Autowired
KafkaTemplate<String, String> kafkaTemplate;
@Override
public void run(ApplicationArguments args)
{
- int num = 10;
-
- if (args.containsOption(ARG_NUM))
- {
- List<String> numArgs = args.getOptionValues(ARG_NUM);
- if (numArgs.size() > 1)
- {
- log.error(
- "Only one occurence of argument {} is allowed, but found: {}",
- ARG_NUM,
- numArgs.size());
- return;
- }
-
- try
- {
- num = Integer.parseInt(numArgs.get(0));
- }
- catch (NumberFormatException e)
- {
- log.error("{} is not a number: {}", numArgs.get(0), e.getMessage());
- }
- }
-
- for (int i = 0; i < num; i++)
+ for (int i = 0; i < 100; i++)
{
send(Long.toString(i%10), Long.toString(i));
- try
- {
- Thread.sleep(500);
- }
- catch (InterruptedException e)
- {
- log.info("Interrupted after sending {} messages", i);
- return;
- }
}
}