You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h4id="writing-typed-records-with-an-avro4s-producer" class="section"><aclass="anchor-link left" href="#writing-typed-records-with-an-avro4s-producer"><iclass="icofont-laika link"></i></a>Writing typed records with an Avro4s producer</h4>
222
222
<p>Turning a generic producer into a typed producer is simple. We first ensure that <code>com.sksamuel.avro4s.RecordFormat</code> instances for our data are in scope:</p>
223
223
<preclass="keep-together pdf epub"><codeclass="nohighlight"><spanclass="keyword">implicit</span><span></span><spanclass="keyword">val</span><span></span><spanclass="type-name">CustomerRecordFormat</span><span> = </span><spanclass="identifier">com</span><span>.</span><spanclass="identifier">sksamuel</span><span>.</span><spanclass="identifier">avro4s</span><span>.</span><spanclass="type-name">RecordFormat</span><span>[</span><spanclass="type-name">Customer</span><span>]
<p>We can now write our typed customer records successfully!</p>
236
236
<preclass="keep-together pdf epub"><codeclass="nohighlight"><spanclass="keyword">import</span><span></span><spanclass="identifier">cats</span><span>.</span><spanclass="identifier">effect</span><span>.</span><spanclass="identifier">unsafe</span><span>.</span><spanclass="identifier">implicits</span><span>.</span><spanclass="identifier">global</span><span>
<p>With our Kafka consumer in hand, we'll assign to our consumer our topic partition, with no offsets, so that it starts reading from the first record, and read a stream of records from our Kafka topic:</p>
269
269
<preclass="keep-together pdf epub"><codeclass="nohighlight"><spanclass="keyword">import</span><span></span><spanclass="identifier">org</span><span>.</span><spanclass="identifier">apache</span><span>.</span><spanclass="identifier">kafka</span><span>.</span><spanclass="identifier">common</span><span>.</span><spanclass="type-name">TopicPartition</span><span>
0 commit comments