Skip to content

Commit

Permalink
deploy: 1cd5601
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Jan 28, 2025
1 parent c32d53c commit df17fa2
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$10733/0x0000000102e31840@3cbdb88d
// resource = cats.effect.kernel.Resource$$$Lambda$10746/0x0000000102e31840@39f8c53a
// )</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@360ff5f5
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@cb26df7
</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@6dc75353</span></code></pre>
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@40372c4c</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$10733/0x0000000102e31840@3cbdb88d
// resource = cats.effect.kernel.Resource$$$Lambda$10746/0x0000000102e31840@39f8c53a
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10861/0x0000000102f35840@592aa660
// fs = cats.effect.kernel.Resource$$Lambda$10874/0x0000000102f35840@2bbd118e
// )</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$10733/0x0000000102e31840@703be9e3
// resource = cats.effect.kernel.Resource$$$Lambda$10746/0x0000000102e31840@505ea9ad
// ),
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10864/0x0000000102f37840@6d8981d0
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10877/0x0000000102f37840@1fd7832
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10861/0x0000000102f35840@4f6ff92c
// fs = cats.effect.kernel.Resource$$Lambda$10874/0x0000000102f35840@3524de51
// )</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 df17fa2

Please sign in to comment.