Skip to content

Commit

Permalink
deploy: 884fd28
Browse files Browse the repository at this point in the history
  • Loading branch information
amohrland committed Aug 5, 2024
1 parent 275921f commit f71e0cc
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$10652/0x0000000102d23040@30bbf25f
// resource = cats.effect.kernel.Resource$$$Lambda$11947/0x00000001030d3040@762cb0b1
// )</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@564277bb
</span><span class="comment">// CustomerRecordFormat: com.sksamuel.avro4s.RecordFormat[Customer] = com.sksamuel.avro4s.RecordFormat$$anon$1@323f7063
</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@40f5d42f</span></code></pre>
</span><span class="comment">// CustomerIdRecordFormat: com.sksamuel.avro4s.RecordFormat[CustomerId] = com.sksamuel.avro4s.RecordFormat$$anon$1@7838db84</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$10652/0x0000000102d23040@30bbf25f
// resource = cats.effect.kernel.Resource$$$Lambda$11947/0x00000001030d3040@762cb0b1
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10780/0x0000000102e6b040@ccac2ff
// fs = cats.effect.kernel.Resource$$Lambda$12075/0x0000000103213840@51a357b8
// )</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$10652/0x0000000102d23040@3d3ccac8
// resource = cats.effect.kernel.Resource$$$Lambda$11947/0x00000001030d3040@7789aaa2
// ),
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$10783/0x0000000102e6c840@73dd1843
// fs = com.banno.kafka.consumer.ConsumerApi$Avro$$$Lambda$12078/0x0000000103215840@6af580b5
// ),
// fs = cats.effect.kernel.Resource$$Lambda$10780/0x0000000102e6b040@5e399768
// fs = cats.effect.kernel.Resource$$Lambda$12075/0x0000000103213840@35f368b6
// )</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 f71e0cc

Please sign in to comment.