@@ -467,7 +467,7 @@ public void testGoodWithSimpleMapper() throws Exception {
467467 @ Test
468468 public void testAggregateNormal () throws Exception {
469469 AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
470- new TopicPartitionOffset (D_REPLY , 0 ), 2 , new AtomicInteger ());
470+ new TopicPartitionOffset (D_REPLY , 0 ), 3 , new AtomicInteger ());
471471 try {
472472 template .setCorrelationHeaderName ("customCorrelation" );
473473 template .setDefaultReplyTimeout (Duration .ofSeconds (30 ));
@@ -477,13 +477,17 @@ public void testAggregateNormal() throws Exception {
477477 future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
478478 ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
479479 future .get (30 , TimeUnit .SECONDS );
480- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
480+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
481481 Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
482482 String value1 = iterator .next ().value ();
483- assertThat (value1 ).isIn ("fOO" , "FOO" );
483+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
484484 String value2 = iterator .next ().value ();
485- assertThat (value2 ).isIn ("fOO" , "FOO" );
485+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
486486 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 );
487491 assertThat (consumerRecord .topic ()).isEqualTo (AggregatingReplyingKafkaTemplate .AGGREGATED_RESULTS_TOPIC );
488492 }
489493 finally {
@@ -495,7 +499,7 @@ public void testAggregateNormal() throws Exception {
495499 @ Test
496500 public void testAggregateNormalStringCorrelation () throws Exception {
497501 AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
498- new TopicPartitionOffset (D_REPLY , 0 ), 2 , new AtomicInteger ());
502+ new TopicPartitionOffset (D_REPLY , 0 ), 3 , new AtomicInteger ());
499503 try {
500504 template .setCorrelationHeaderName ("customCorrelation" );
501505 template .setBinaryCorrelation (false );
@@ -506,13 +510,17 @@ public void testAggregateNormalStringCorrelation() throws Exception {
506510 future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
507511 ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
508512 future .get (30 , TimeUnit .SECONDS );
509- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
513+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
510514 Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
511515 String value1 = iterator .next ().value ();
512- assertThat (value1 ).isIn ("fOO" , "FOO" );
516+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
513517 String value2 = iterator .next ().value ();
514- assertThat (value2 ).isIn ("fOO" , "FOO" );
518+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
515519 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 );
516524 assertThat (consumerRecord .topic ()).isEqualTo (AggregatingReplyingKafkaTemplate .AGGREGATED_RESULTS_TOPIC );
517525 }
518526 finally {
@@ -526,7 +534,7 @@ public void testAggregateNormalStringCorrelation() throws Exception {
526534 @ Disabled ("time sensitive" )
527535 public void testAggregateTimeout () throws Exception {
528536 AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
529- new TopicPartitionOffset (E_REPLY , 0 ), 3 , new AtomicInteger ());
537+ new TopicPartitionOffset (E_REPLY , 0 ), 4 , new AtomicInteger ());
530538 try {
531539 template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
532540 template .setCorrelationHeaderName ("customCorrelation" );
@@ -561,7 +569,7 @@ public void testAggregateTimeout() throws Exception {
561569 public void testAggregateTimeoutPartial () throws Exception {
562570 AtomicInteger releaseCount = new AtomicInteger ();
563571 AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
564- new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
572+ new TopicPartitionOffset (F_REPLY , 0 ), 4 , releaseCount );
565573 template .setReturnPartialOnTimeout (true );
566574 try {
567575 template .setDefaultReplyTimeout (Duration .ofSeconds (5 ));
@@ -572,16 +580,20 @@ public void testAggregateTimeoutPartial() throws Exception {
572580 future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
573581 ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
574582 future .get (30 , TimeUnit .SECONDS );
575- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
583+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
576584 Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
577585 String value1 = iterator .next ().value ();
578- assertThat (value1 ).isIn ("fOO" , "FOO" );
586+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
579587 String value2 = iterator .next ().value ();
580- assertThat (value2 ).isIn ("fOO" , "FOO" );
588+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
581589 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 );
582594 assertThat (consumerRecord .topic ())
583595 .isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
584- assertThat (releaseCount .get ()).isEqualTo (3 );
596+ assertThat (releaseCount .get ()).isEqualTo (4 );
585597 }
586598 finally {
587599 template .stop ();
@@ -593,7 +605,7 @@ public void testAggregateTimeoutPartial() throws Exception {
593605 public void testAggregateTimeoutPartialStringCorrelation () throws Exception {
594606 AtomicInteger releaseCount = new AtomicInteger ();
595607 AggregatingReplyingKafkaTemplate <Integer , String , String > template = aggregatingTemplate (
596- new TopicPartitionOffset (F_REPLY , 0 ), 3 , releaseCount );
608+ new TopicPartitionOffset (F_REPLY , 0 ), 4 , releaseCount );
597609 template .setReturnPartialOnTimeout (true );
598610 template .setBinaryCorrelation (false );
599611 try {
@@ -605,16 +617,20 @@ public void testAggregateTimeoutPartialStringCorrelation() throws Exception {
605617 future .getSendFuture ().get (10 , TimeUnit .SECONDS ); // send ok
606618 ConsumerRecord <Integer , Collection <ConsumerRecord <Integer , String >>> consumerRecord =
607619 future .get (30 , TimeUnit .SECONDS );
608- assertThat (consumerRecord .value ().size ()).isEqualTo (2 );
620+ assertThat (consumerRecord .value ().size ()).isEqualTo (3 );
609621 Iterator <ConsumerRecord <Integer , String >> iterator = consumerRecord .value ().iterator ();
610622 String value1 = iterator .next ().value ();
611- assertThat (value1 ).isIn ("fOO" , "FOO" );
623+ assertThat (value1 ).isIn ("fOO" , "FOO" , "Foo" );
612624 String value2 = iterator .next ().value ();
613- assertThat (value2 ).isIn ("fOO" , "FOO" );
625+ assertThat (value2 ).isIn ("fOO" , "FOO" , "Foo" );
614626 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 );
615631 assertThat (consumerRecord .topic ())
616632 .isEqualTo (AggregatingReplyingKafkaTemplate .PARTIAL_RESULTS_AFTER_TIMEOUT_TOPIC );
617- assertThat (releaseCount .get ()).isEqualTo (3 );
633+ assertThat (releaseCount .get ()).isEqualTo (4 );
618634 }
619635 finally {
620636 template .stop ();
@@ -865,6 +881,17 @@ public ConcurrentKafkaListenerContainerFactory<Integer, String> kafkaListenerCon
865881 return factory ;
866882 }
867883
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+
868895 @ Bean
869896 public ConcurrentKafkaListenerContainerFactory <Integer , String > simpleMapperFactory () {
870897 ConcurrentKafkaListenerContainerFactory <Integer , String > factory =
@@ -921,22 +948,30 @@ public HandlerReturn handlerReturn() {
921948 return new HandlerReturn ();
922949 }
923950
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" )
925953 @ SendTo // default REPLY_TOPIC header
926954 public Message <String > dListener1 (String in , @ Header ("customCorrelation" ) byte [] correlation ) {
927955 return MessageBuilder .withPayload (in .toUpperCase ())
928956 .setHeader ("customCorrelation" , correlation )
929957 .build ();
930958 }
931959
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" )
933962 @ SendTo // default REPLY_TOPIC header
934- public Message <String > dListener2 (String in , @ Header ( "customCorrelation" ) byte [] correlation ) {
963+ public Message <String > dListener2 (String in ) {
935964 return MessageBuilder .withPayload (in .substring (0 , 1 ) + in .substring (1 ).toUpperCase ())
936- .setHeader ("customCorrelation" , correlation )
937965 .build ();
938966 }
939967
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+
940975 @ KafkaListener (id = G_REQUEST , topics = G_REQUEST )
941976 public void gListener (Message <String > in ) {
942977 String replyTopic = new String (in .getHeaders ().get ("custom.reply.to" , byte [].class ));
0 commit comments