datasourcex-java-flow

Provides an API for binding implementations of Java's Flow to subjects and channels provided by Caplin DataSource.
This library is designed for use from both Java and Kotlin.

Alternative Implementation

For most projects it is recommended to use the datasourcex-reactivestreams module instead, as it provides better compatibility with reactive libraries such as RxJava, Reactor & Akka Streams.

See also

Samples

import com.caplin.datasource.DataSource
import com.caplin.integration.datasourcex.reactive.api.RecordType
import com.caplin.integration.datasourcex.reactive.java.Bind
import java.time.Duration
import org.reactivestreams.FlowAdapters
import reactor.core.publisher.Flux

fun main() { 
   //sampleStart 
   Bind.using(dataSource) {
  to("my-service") {
    active {
      record {
        path(
            path = "/example/activeSubject",
            publisher =
                FlowAdapters.toFlowPublisher(
                    Flux.interval(Duration.ofSeconds(1)).map { aLong: Long ->
                      mapOf("Count" to aLong.toString())
                    }),
        ) {
          recordType = RecordType.TYPE1
        }
      }

      json {
        pattern(
            pattern = "/example/{username}/subjectPattern/{myKey}",
            configure = { objectMappings = mapOf("username" to "%u") },
            supplier = { _, parameters ->
              val username = parameters["username"]
              val myKey = parameters["myKey"]
              FlowAdapters.toFlowPublisher(
                  Flux.interval(Duration.ofSeconds(1)).map { count: Long ->
                    JsonObject("$username $myKey $count")
                  })
            },
        )
      }
    }
  }
} 
   //sampleEnd
}

Packages