@@ -1,14 +1,29 @@
1−module Kafka.Producer where
1+module Kafka.Producer
8+ , InternalProducerMessage
9+ , InternalProducerBatch
10+ , toInternalProducerMessage
11+ , toInternalProducerBatch
3−import Prelude (Unit, (#), (>>>))
17+import Prelude (Unit, (#), (>>>), (<#>))
4import Control.Promise (Promise, toAffE)
18import Control.Promise (Promise, toAffE)
5import Data.Function.Uncurried (Fn2, runFn2)
19import Data.Function.Uncurried (Fn2, runFn2)
6import Data.Maybe (Maybe)
20import Data.Maybe (Maybe)
7import Data.Nullable (Nullable, toNullable)
21import Data.Nullable (Nullable, toNullable)
8import Effect (Effect)
22import Effect (Effect)
9import Effect.Aff (Aff)
23import Effect.Aff (Aff)
10−import Kafka.Kafka (Kafka, Payload, RecordMetadata)
24+import Kafka.Kafka (Kafka)
11−import Kafka.Internal.Internal (InternalPayload, convert)
25+import Kafka.Types (Partition(..), Topic(..))
26+import Data.Newtype (un)
13foreign import data Producer :: Type
28foreign import data Producer :: Type
@@ -32,7 +47,7 @@ makeProducer k pc = runFn2 makeProducerImpl k ipc
33 { idempotent: toNullable pc.idempotent
48 { idempotent: toNullable pc.idempotent
34 , transactionalId: toNullable pc.transactionalId
49 , transactionalId: toNullable pc.transactionalId
35− , maxInFlightRequests : toNullable pc.maxInFlightRequests
50+ , maxInFlightRequests: toNullable pc.maxInFlightRequests
38foreign import connectImpl :: Producer -> Effect (Promise Unit)
53foreign import connectImpl :: Producer -> Effect (Promise Unit)
@@ -40,10 +55,40 @@ foreign import connectImpl :: Producer -> Effect (Promise Unit)
40connect :: Producer -> Aff Unit
55connect :: Producer -> Aff Unit
41connect = connectImpl >>> toAffE
56connect = connectImpl >>> toAffE
59+ = { key :: Maybe String
61+ , partition :: Maybe Partition
66+ , messages :: Array (ProducerMessage)
69+foreign import data RecordMetadata :: Type
71+type InternalProducerMessage
72+ = { key :: Nullable String
74+ , partition :: Nullable Int
77+type InternalProducerBatch
79+ , messages :: Array (InternalProducerMessage)
82+toInternalProducerMessage :: ProducerMessage -> InternalProducerMessage
83+toInternalProducerMessage { key, value, partition: partition } = { key: toNullable key, value: value, partition: partition <#> un Partition # toNullable }
85+toInternalProducerBatch :: ProducerBatch -> InternalProducerBatch
86+toInternalProducerBatch { topic: Topic topic, messages } = { topic, messages: messages <#> toInternalProducerMessage }
43−foreign import sendImpl :: Fn2 Producer InternalPayload (Effect (Promise (Array RecordMetadata)))
88+foreign import sendImpl :: Fn2 Producer InternalProducerBatch (Effect (Promise (Array RecordMetadata)))
45−send :: Producer -> Payload -> Aff (Array RecordMetadata)
90+send :: Producer -> ProducerBatch -> Aff (Array RecordMetadata)
46−send p pl = runFn2 sendImpl p (convert pl) # toAffE
91+send p pl = runFn2 sendImpl p (toInternalProducerBatch pl) # toAffE
48foreign import disconnectImpl :: Producer -> Effect (Promise Unit)
93foreign import disconnectImpl :: Producer -> Effect (Promise Unit)