Skip to content

Commit

Permalink
deploy: a5ec477
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Sep 2, 2024
1 parent fbcc3ab commit 4200837
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ <h3 id="write-our-records-to-kafka" class="section"><a class="anchor-link left"
</span><span class="type-name">ClientId</span><span>(</span><span class="string-literal">&quot;producer-example&quot;</span><span>)
)
</span><span class="comment">// producer: Resource[IO, ProducerApi[IO, org.apache.avro.generic.GenericRecord, org.apache.avro.generic.GenericRecord]] = Allocate(
// resource = cats.effect.kernel.Resource$$$Lambda$10750/0x0000000102f43040@2d283654
// resource = cats.effect.kernel.Resource$$$Lambda$10734/0x0000000102d1b040@3f667b9b
// )</span></code></pre>
<p>And we&#39;ll define some customer records to be written:</p>
<pre><code class="nohighlight"><span class="keyword">import</span><span> </span><span class="identifier">org</span><span>.</span><span class="identifier">apache</span><span>.</span><span class="identifier">kafka</span><span>.</span><span class="identifier">clients</span><span>.</span><span class="identifier">producer</span><span>.</span><span class="type-name">ProducerRecord</span><span>
Expand Down Expand Up @@ -221,16 +221,16 @@ <h3 id="write-our-records-to-kafka" class="section"><a class="anchor-link left"
<h4 id="writing-typed-records-with-an-avro4s-producer" class="section"><a class="anchor-link left" href="#writing-typed-records-with-an-avro4s-producer"><i class="icofont-laika link">&#xef71;</i></a>Writing typed records with an Avro4s producer</h4>
<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>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">implicit</span><span> </span><span class="keyword">val</span><span> </span><span class="type-name">CustomerRecordFormat</span><span> = </span><span class="identifier">com</span><span>.</span><span class="identifier">sksamuel</span><span>.</span><span class="identifier">avro4s</span><span>.</span><span class="type-name">RecordFormat</span><span>[</span><span class="type-name">Customer</span><span>]
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@732d290c
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@1c808a0f
</span><span class="keyword">implicit</span><span> </span><span class="keyword">val</span><span> </span><span class="type-name">CustomerIdRecordFormat</span><span> = </span><span class="identifier">com</span><span>.</span><span class="identifier">sksamuel</span><span>.</span><span class="identifier">avro4s</span><span>.</span><span class="type-name">RecordFormat</span><span>[</span><span class="type-name">CustomerId</span><span>]
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@22102415</span></code></pre>
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@e72307a</span></code></pre>
<p>And with those implicits in scope, we can create our producer:</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">val</span><span> </span><span class="identifier">avro4sProducer</span><span> = </span><span class="identifier">producer</span><span>.</span><span class="identifier">map</span><span>(</span><span class="identifier">_</span><span>.</span><span class="identifier">toAvro4s</span><span>[</span><span class="type-name">CustomerId</span><span>, </span><span class="type-name">Customer</span><span>])
</span><span class="comment">// avro4sProducer: Resource[IO, ProducerApi[[A]IO[A], CustomerId, Customer]] = Bind(
// source = Allocate(
// resource = cats.effect.kernel.Resource$$$Lambda$10750/0x0000000102f43040@2d283654
// resource = cats.effect.kernel.Resource$$$Lambda$10734/0x0000000102d1b040@3f667b9b
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10878/0x000000010308a040@3781bf7e
// fs = cats.effect.kernel.Resource$$Lambda$10862/0x0000000102e63040@64d23496
// )</span></code></pre>
<p>We can now write our typed customer records successfully!</p>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">import</span><span> </span><span class="identifier">cats</span><span>.</span><span class="identifier">effect</span><span>.</span><span class="identifier">unsafe</span><span>.</span><span class="identifier">implicits</span><span>.</span><span class="identifier">global</span><span>
Expand Down Expand Up @@ -259,11 +259,11 @@ <h3 id="read-our-records-from-kafka" class="section"><a class="anchor-link left"
</span><span class="comment">// consumer: Resource[IO, ConsumerApi[IO, CustomerId, Customer]] = Bind(
// source = Bind(
// source = Allocate(
// resource = cats.effect.kernel.Resource$$$Lambda$10750/0x0000000102f43040@6bc2333f
// resource = cats.effect.kernel.Resource$$$Lambda$10734/0x0000000102d1b040@26c8d91d
// ),
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10881/0x000000010308c040@3510b8b0
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10865/0x0000000102e65040@9bace14
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10878/0x000000010308a040@3ed47a0
// fs = cats.effect.kernel.Resource$$Lambda$10862/0x0000000102e63040@29767acf
// )</span></code></pre>
<p>With our Kafka consumer in hand, we&#39;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>
<pre class="keep-together pdf epub"><code class="nohighlight"><span class="keyword">import</span><span> </span><span class="identifier">org</span><span>.</span><span class="identifier">apache</span><span>.</span><span class="identifier">kafka</span><span>.</span><span class="identifier">common</span><span>.</span><span class="type-name">TopicPartition</span><span>
Expand Down

0 comments on commit 4200837

Please sign in to comment.