title: RecordTooLargeException in Kafka streams join
body: <p>I have a KStream x KStream join which is breaking down with the following exception.</p>
  
  <pre><code>Exception in thread “my-clicks-and-recs-join-streams-4c903fb1-5938-4919-9c56-2c8043b86986-StreamThread-1" org.apache.kafka.streams.errors.StreamsException: Exception caught in process. taskId=0_15, processor=KSTREAM-SOURCE-0000000001, topic=my_outgoing_recs_prod, partition=15, offset=9248896
      at org.apache.kafka.streams.processor.internals.StreamTask.process(StreamTask.java:203)
      at org.apache.kafka.streams.processor.internals.StreamThread.processAndPunctuate(StreamThread.java:679)
      at org.apache.kafka.streams.processor.internals.StreamThread.runLoop(StreamThread.java:557)
      at org.apache.kafka.streams.processor.internals.StreamThread.run(StreamThread.java:527)
  Caused by: org.apache.kafka.streams.errors.StreamsException: task [0_15] exception caught when producing
      at org.apache.kafka.streams.processor.internals.RecordCollectorImpl.checkForException(RecordCollectorImpl.java:136)
      at org.apache.kafka.streams.processor.internals.RecordCollectorImpl.send(RecordCollectorImpl.java:87)
      at org.apache.kafka.streams.state.internals.StoreChangeLogger.logChange(StoreChangeLogger.java:59)
      at org.apache.kafka.streams.state.internals.ChangeLoggingSegmentedBytesStore.put(ChangeLoggingSegmentedBytesStore.java:59)
      at org.apache.kafka.streams.state.internals.MeteredSegmentedBytesStore.put(MeteredSegmentedBytesStore.java:105)
      at org.apache.kafka.streams.state.internals.RocksDBWindowStore.put(RocksDBWindowStore.java:107)
      at org.apache.kafka.streams.state.internals.RocksDBWindowStore.put(RocksDBWindowStore.java:100)
      at org.apache.kafka.streams.kstream.internals.KStreamJoinWindow$KStreamJoinWindowProcessor.process(KStreamJoinWindow.java:64)
      at org.apache.kafka.streams.processor.internals.ProcessorNode$1.run(ProcessorNode.java:47)
      at org.apache.kafka.streams.processor.internals.StreamsMetricsImpl.measureLatencyNs(StreamsMetricsImpl.java:187)
      at org.apache.kafka.streams.processor.internals.ProcessorNode.process(ProcessorNode.java:133)
      at org.apache.kafka.streams.processor.internals.ProcessorContextImpl.forward(ProcessorContextImpl.java:82)
      at org.apache.kafka.streams.processor.internals.SourceNode.process(SourceNode.java:80)
      at org.apache.kafka.streams.processor.internals.StreamTask.process(StreamTask.java:189)
      ... 3 more
  Caused by: org.apache.kafka.common.errors.RecordTooLargeException: The request included a message larger than the max message size the server will accept.
  </code></pre>
  
  <p>I am joining a <code>Click</code> topic with a <code>Recommendation</code> topic. The <code>Click</code> objects are really small (less than a KB). <code>Recommendation</code>, on the other hand, might be big, occasionally bigger than 1 MB.</p>
  
  <p>I Googled for the exception and found ( <a href="https://stackoverflow.com/questions/42507494/org-apache-kafka-common-errors-recordtoolargeexception-in-flume-kafka-sink">here</a>) that I need to set <code>max.request.size</code> in the producer configs.</p>
  
  <p>What I don't understand is, where does the producer come into picture in the streams join? The topic in the exception above <code>topic=my_outgoing_recs_prod</code> is the recommendations topic, and not the final joined topic. Isn't the streaming application supposed to just "consume" from it?</p>
  
  <p>Nevertheless, I tried setting the property as <code>config.put("max.request.size", "31457280");</code>, which is 30MB. I don't expect the recommendations record to exceed that limit. Still, the code is crashing.</p>
  
  <p>I cannot change the configs in the Kafka cluster but, if needed, I can change the properties of the relevant topics in Kafka.</p>
  
  <p>Could someone suggest what else I can try?</p>
  
  <p>If nothing works, I am willing to ignore such oversizes messages. However, I don't know a way of handling this <code>RecordTooLargeException</code>.</p>
  
  <p>My code to perform the join is as follows.</p>
  
  <pre><code>Properties config = new Properties();
  config.put(StreamsConfig.APPLICATION_ID_CONFIG, JOINER_ID + "-" + System.getenv("HOSTNAME"));
  config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, booststrapList);
  config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
  config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.ByteArray().getClass().getName());
  config.put("max.request.size", "314572800");
  config.put("message.max.bytes", "314572800");
  config.put("max.message.bytes", "314572800");
  
  
  KStreamBuilder builder = new KStreamBuilder();
  
  KStream&lt;String, byte[]&gt; clicksStream = builder.stream(TopologyBuilder.AutoOffsetReset.LATEST, Serdes.String(), Serdes.ByteArray(), clicksTopic);
  KStream&lt;String, byte[]&gt; recsStream = builder.stream(TopologyBuilder.AutoOffsetReset.LATEST, Serdes.String(), Serdes.ByteArray(), recsTopic);
  
  KStream&lt;String, ClickRec&gt; join = clicksStream.join(
          recsStream,
          (click, recs) -&gt; new ClickRec(click, recs),
          JoinWindows.of(windowMillis).until(3*windowMillis));
  
  join.to(Serdes.String(), JoinSerdes.CLICK_SERDE, jointTopic);
  
  KafkaStreams streams = new KafkaStreams(builder, config);
  streams.cleanUp();
  streams.start();
  </code></pre>
  
  <p><code>ClickRec</code> is the joined object (which is far smaller than a <code>Recommendation</code> object and I don't expect it to be bigger than a few KBs).</p>
  
  <p>Where do I put a <code>try...catch</code> in the code above to recover from such occasionally oversized objects?</p>