@@ -467,7 +467,7 @@ public void testGoodWithSimpleMapper() throws Exception {
467
467
@ Test
468
468
public void testAggregateNormal () throws Exception {
469
469
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
470
- new TopicPartitionOffset (D_REPLY , 0 ), 2 , new AtomicInteger ());
470
+ new TopicPartitionOffset (D_REPLY , 0 ), 3 , new AtomicInteger ());
471
471
try {
472
472
template .setCorrelationHeaderName ("customCorrelation" );
473
473
template .setDefaultReplyTimeout (Duration .ofSeconds (30 ));
@@ -477,13 +477,17 @@ public void testAggregateNormal() throws Exception {
477
477
future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
478
478
ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
479
479
future .get (30 , TimeUnit .SECONDS );
480
- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
480
+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
481
481
Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
482
482
String value1 = iterator .next ().value ();
483
- assertThat (value1 ).isIn ("fOO" , "FOO" );
483
+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
484
484
String value2 = iterator .next ().value ();
485
- assertThat (value2 ).isIn ("fOO" , "FOO" );
485
+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
486
486
assertThat (value2 ).isNotSameAs (value1 );
487
+ String value3 = iterator .next ().value ();
488
+ assertThat (value3 ).isIn ("fOO" , "FOO" , "Foo" );
489
+ assertThat (value3 ).isNotSameAs (value1 );
490
+ assertThat (value3 ).isNotSameAs (value2 );
487
491
assertThat (consumerRecord .topic ()).isEqualTo (AggregatingReplyingKafkaTemplate .AGGREGATED_RESULTS_TOPIC );
488
492
}
489
493
finally {
@@ -495,7 +499,7 @@ public void testAggregateNormal() throws Exception {
495
499
@ Test
496
500
public void testAggregateNormalStringCorrelation () throws Exception {
497
501
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
498
- new TopicPartitionOffset (D_REPLY , 0 ), 2 , new AtomicInteger ());
502
+ new TopicPartitionOffset (D_REPLY , 0 ), 3 , new AtomicInteger ());
499
503
try {
500
504
template .setCorrelationHeaderName ("customCorrelation" );
501
505
template .setBinaryCorrelation (false );
@@ -506,13 +510,17 @@ public void testAggregateNormalStringCorrelation() throws Exception {
506
510
future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
507
511
ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
508
512
future .get (30 , TimeUnit .SECONDS );
509
- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
513
+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
510
514
Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
511
515
String value1 = iterator .next ().value ();
512
- assertThat (value1 ).isIn ("fOO" , "FOO" );
516
+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
513
517
String value2 = iterator .next ().value ();
514
- assertThat (value2 ).isIn ("fOO" , "FOO" );
518
+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
515
519
assertThat (value2 ).isNotSameAs (value1 );
520
+ String value3 = iterator .next ().value ();
521
+ assertThat (value3 ).isIn ("fOO" , "FOO" , "Foo" );
522
+ assertThat (value3 ).isNotSameAs (value1 );
523
+ assertThat (value3 ).isNotSameAs (value2 );
516
524
assertThat (consumerRecord .topic ()).isEqualTo (AggregatingReplyingKafkaTemplate .AGGREGATED_RESULTS_TOPIC );
517
525
}
518
526
finally {
@@ -526,7 +534,7 @@ public void testAggregateNormalStringCorrelation() throws Exception {
526
534
@ Disabled ("time sensitive" )
527
535
public void testAggregateTimeout () throws Exception {
528
536
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
529
- new TopicPartitionOffset (E_REPLY , 0 ), 3 , new AtomicInteger ());
537
+ new TopicPartitionOffset (E_REPLY , 0 ), 4 , new AtomicInteger ());
530
538
try {
531
539
template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
532
540
template .setCorrelationHeaderName ("customCorrelation" );
@@ -561,7 +569,7 @@ public void testAggregateTimeout() throws Exception {
561
569
public void testAggregateTimeoutPartial () throws Exception {
562
570
AtomicInteger releaseCount = new AtomicInteger ();
563
571
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
564
- new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
572
+ new TopicPartitionOffset (F_REPLY , 0 ), 4 , releaseCount );
565
573
template .setReturnPartialOnTimeout (true );
566
574
try {
567
575
template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
@@ -572,16 +580,20 @@ public void testAggregateTimeoutPartial() throws Exception {
572
580
future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
573
581
ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
574
582
future .get (30 , TimeUnit .SECONDS );
575
- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
583
+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
576
584
Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
577
585
String value1 = iterator .next ().value ();
578
- assertThat (value1 ).isIn ("fOO" , "FOO" );
586
+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
579
587
String value2 = iterator .next ().value ();
580
- assertThat (value2 ).isIn ("fOO" , "FOO" );
588
+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
581
589
assertThat (value2 ).isNotSameAs (value1 );
590
+ String value3 = iterator .next ().value ();
591
+ assertThat (value3 ).isIn ("fOO" , "FOO" , "Foo" );
592
+ assertThat (value3 ).isNotSameAs (value1 );
593
+ assertThat (value3 ).isNotSameAs (value2 );
582
594
assertThat (consumerRecord .topic ())
583
595
.isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
584
- assertThat (releaseCount .get ()).isEqualTo (3 );
596
+ assertThat (releaseCount .get ()).isEqualTo (4 );
585
597
}
586
598
finally {
587
599
template .stop ();
@@ -593,7 +605,7 @@ public void testAggregateTimeoutPartial() throws Exception {
593
605
public void testAggregateTimeoutPartialStringCorrelation () throws Exception {
594
606
AtomicInteger releaseCount = new AtomicInteger ();
595
607
AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
596
- new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
608
+ new TopicPartitionOffset (F_REPLY , 0 ), 4 , releaseCount );
597
609
template .setReturnPartialOnTimeout (true );
598
610
template .setBinaryCorrelation (false );
599
611
try {
@@ -605,16 +617,20 @@ public void testAggregateTimeoutPartialStringCorrelation() throws Exception {
605
617
future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
606
618
ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
607
619
future .get (30 , TimeUnit .SECONDS );
608
- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
620
+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
609
621
Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
610
622
String value1 = iterator .next ().value ();
611
- assertThat (value1 ).isIn ("fOO" , "FOO" );
623
+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
612
624
String value2 = iterator .next ().value ();
613
- assertThat (value2 ).isIn ("fOO" , "FOO" );
625
+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
614
626
assertThat (value2 ).isNotSameAs (value1 );
627
+ String value3 = iterator .next ().value ();
628
+ assertThat (value3 ).isIn ("fOO" , "FOO" , "Foo" );
629
+ assertThat (value3 ).isNotSameAs (value1 );
630
+ assertThat (value3 ).isNotSameAs (value2 );
615
631
assertThat (consumerRecord .topic ())
616
632
.isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
617
- assertThat (releaseCount .get ()).isEqualTo (3 );
633
+ assertThat (releaseCount .get ()).isEqualTo (4 );
618
634
}
619
635
finally {
620
636
template .stop ();
@@ -865,6 +881,17 @@ public ConcurrentKafkaListenerContainerFactory<Integer, String> kafkaListenerCon
865
881
return factory ;
866
882
}
867
883
884
+ @ Bean
885
+ public ConcurrentKafkaListenerContainerFactory <Integer , String > customListenerContainerFactory () {
886
+ ConcurrentKafkaListenerContainerFactory <Integer , String > factory =
887
+ new ConcurrentKafkaListenerContainerFactory <>();
888
+ factory .setConsumerFactory (cf ());
889
+ factory .setReplyTemplate (template ());
890
+ factory .setCorrelationHeaderName ("customCorrelation" );
891
+ factory .setMissingTopicsFatal (false );
892
+ return factory ;
893
+ }
894
+
868
895
@ Bean
869
896
public ConcurrentKafkaListenerContainerFactory <Integer , String > simpleMapperFactory () {
870
897
ConcurrentKafkaListenerContainerFactory <Integer , String > factory =
@@ -921,22 +948,30 @@ public HandlerReturn handlerReturn() {
921
948
return new HandlerReturn ();
922
949
}
923
950
924
- @ KafkaListener (id = "def1" , topics = { D_REQUEST , E_REQUEST , F_REQUEST })
951
+ @ KafkaListener (id = "def1" , topics = { D_REQUEST , E_REQUEST , F_REQUEST },
952
+ containerFactory = "customListenerContainerFactory" )
925
953
@ SendTo // default REPLY_TOPIC header
926
954
public Message <String > dListener1 (String in , @ Header ("customCorrelation" ) byte [] correlation ) {
927
955
return MessageBuilder .withPayload (in .toUpperCase ())
928
956
.setHeader ("customCorrelation" , correlation )
929
957
.build ();
930
958
}
931
959
932
- @ KafkaListener (id = "def2" , topics = { D_REQUEST , E_REQUEST , F_REQUEST })
960
+ @ KafkaListener (id = "def2" , topics = { D_REQUEST , E_REQUEST , F_REQUEST },
961
+ containerFactory = "customListenerContainerFactory" )
933
962
@ SendTo // default REPLY_TOPIC header
934
- public Message <String > dListener2 (String in , @ Header ( "customCorrelation" ) byte [] correlation ) {
963
+ public Message <String > dListener2 (String in ) {
935
964
return MessageBuilder .withPayload (in .substring (0 , 1 ) + in .substring (1 ).toUpperCase ())
936
- .setHeader ("customCorrelation" , correlation )
937
965
.build ();
938
966
}
939
967
968
+ @ KafkaListener (id = "def3" , topics = { D_REQUEST , E_REQUEST , F_REQUEST },
969
+ containerFactory = "customListenerContainerFactory" )
970
+ @ SendTo // default REPLY_TOPIC header
971
+ public String dListener3 (String in ) {
972
+ return in .substring (0 , 1 ).toUpperCase () + in .substring (1 );
973
+ }
974
+
940
975
@ KafkaListener (id = G_REQUEST , topics = G_REQUEST )
941
976
public void gListener (Message <String > in ) {
942
977
String replyTopic = new String (in .getHeaders ().get ("custom.reply.to" , byte [].class ));
0 commit comments