https://github.com/cyberdelia/motion
  
  
    Kinesis producer optimized for random partition keys. 
    https://github.com/cyberdelia/motion
  
kinesis kotlin
        Last synced: 7 months ago 
        JSON representation
    
Kinesis producer optimized for random partition keys.
- Host: GitHub
- URL: https://github.com/cyberdelia/motion
- Owner: cyberdelia
- Created: 2022-07-24T15:53:56.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T15:39:20.000Z (over 1 year ago)
- Last Synced: 2024-05-02T05:54:00.803Z (over 1 year ago)
- Topics: kinesis, kotlin
- Language: Kotlin
- Homepage: https://github.com/cyberdelia/motion
- Size: 243 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          # Motion
Motion is Kinesis producer optimized for random partition keys.
### Installation
Add the library to your gradle dependencies:
```kotlin
dependencies {
    implementation("com.lapanthere:motion:0.1")
}
```
### Usage
To create a stream:
```kotlin
val stream = Stream("kinesis-stream", serializer = { value -> objectMapper.writeValueAsBytes(value) })
```
To publish to the stream:
```kotlin
val future = stream.publish(event, expires = Duration.ofSeconds(1))
```
Ensure you close the stream before shutting down your application:
```kotlin
stream.close()
```
#### Interceptors
You can specify interceptors that are allowed to intercept records before and after publication.
Interceptors are also allowed to mutate the record before publication, each interceptor receives the record returned by
the previous interceptor in the chain.
```kotlin
class MetricsInterceptor : Interceptor {
    override fun beforePublication(record: Record, context: Context): Record {
        Metrics.count("kinesis.publication.count").increment()
        return record
    }
    override fun afterPublication(receipt: Receipt?, throwable: Throwable?, context: Context) {
        if (receipt != null) {
            Metrics.timer("kinesis.publication.latency", "shard_id", receipt.shardID)
                .record(receipt.duration)
        }
    }
}
val stream = Stream(
    "stream-name", serializer = { value -> objectMapper.writeValueAsBytes(value) },
    interceptors = listOf(MetricsInterceptor())
)
```