@SpringBootApplication@EnableAsync@Slf4jpublicclass MyApplication implements CommandLineRunner {
@Autowiredprivate MyAsyncService myAsyncService;
publicstaticvoid main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Overridepublicvoid run(String... args) throws Exception {
log.info("start app");
try {
// max pool size:2, queue size:1
myAsyncService.executeAsyncProcess(); // will be executed
myAsyncService.executeAsyncProcess(); // will be executed on another thread
myAsyncService.executeAsyncProcess(); // will be queued
myAsyncService.executeAsyncProcess(); // will not be executed due to shortage of thread pool
} catch (TaskRejectedException e) {
log.warn(e.getMessage());
}
log.info("finish app");
}
}
import json
from collections import OrderedDict
import sys
REMOVE_ITEM_LIST = ["remove_target1", "remove_target2"]
defremove_fields(arg):
ifisinstance(arg, list):
for item in arg:
remove_fields(item)
elifisinstance(arg, dict):
for remove_item in REMOVE_ITEM_LIST:
if remove_item in arg:
del(arg[remove_item])
for value in arg.values():
remove_fields(value)
if __name__ == '__main__':
args = sys.argv
path = args[1]
withopen(path) as f:
od = json.load(f, object_pairs_hook=OrderedDict)
remove_fields(od)
print(json.dumps(od, indent=2, ensure_ascii=False))
# topic list
$ kcat -b localhost:9092 -t new_topic -C
% Reached end of topic new_topic [0] at offset 0
test
test2
% Reached end of topic new_topic [0] at offset 2
test3
% Reached end of topic new_topic [0] at offset 3
topic list
# topic list
$ kcat -b localhost:9092 -L
Metadata for all topics (from broker 1: localhost:9092/1):
1 brokers:
broker 1 at localhost:9092 (controller)
1 topics:
topic "new_topic" with 1 partitions:
partition 0, leader 1, replicas: 1, isrs: 1