Skip to content

Commit

Permalink
deploy: 0b894b7
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Dec 4, 2024
1 parent b79b6cb commit 2d80cf9
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$10701/0x0000000102d91040@53acb620
// resource = cats.effect.kernel.Resource$$$Lambda$10909/0x0000000102d99840@1b2c90b
// )</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@7c6cc445
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@199ded2
</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@5ecb9b59</span></code></pre>
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@1ed4cf89</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$10701/0x0000000102d91040@53acb620
// resource = cats.effect.kernel.Resource$$$Lambda$10909/0x0000000102d99840@1b2c90b
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10829/0x0000000102e95040@484bea6c
// fs = cats.effect.kernel.Resource$$Lambda$11037/0x0000000102e9d840@1917affb
// )</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$10701/0x0000000102d91040@37317808
// resource = cats.effect.kernel.Resource$$$Lambda$10909/0x0000000102d99840@c4af167
// ),
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10832/0x0000000102e96040@5f2c66c1
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$11040/0x0000000102e9f840@5b237aa1
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10829/0x0000000102e95040@36dae9e9
// fs = cats.effect.kernel.Resource$$Lambda$11037/0x0000000102e9d840@35618a11
// )</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 2d80cf9

Please sign in to comment.