Skip to content

Commit

Permalink
deploy: 34170d2
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Nov 16, 2023
1 parent 71bbcb4 commit 0e7df1b
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 @@ -186,7 +186,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$10716/0x0000000102d83040@1b3f844e
// resource = cats.effect.kernel.Resource$$$Lambda$10767/0x0000000102d83040@4d65135
// )</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 @@ -217,16 +217,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@5803e68
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@68aed82a
</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@778131e7</span></code></pre>
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@76e273f0</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$10716/0x0000000102d83040@1b3f844e
// resource = cats.effect.kernel.Resource$$$Lambda$10767/0x0000000102d83040@4d65135
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10809/0x0000000102eb1840@3a6ce45d
// fs = cats.effect.kernel.Resource$$Lambda$10860/0x0000000102eb2040@69a9b6d5
// )</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 @@ -255,11 +255,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$10716/0x0000000102d83040@62dba593
// resource = cats.effect.kernel.Resource$$$Lambda$10767/0x0000000102d83040@1c8b5f3d
// ),
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10812/0x0000000102eb3840@662ca4de
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10863/0x0000000102eb4040@2faab0e
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10809/0x0000000102eb1840@185cbff5
// fs = cats.effect.kernel.Resource$$Lambda$10860/0x0000000102eb2040@67e23552
// )</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 0e7df1b

Please sign in to comment.