Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Provides play-json support for the various nakadi-klients models.

License

Notifications You must be signed in to change notification settings

zalando-nakadi/nakadi-klients-play-json

Repository files navigation

Nakadi Klients Play Json Support

Provides play-json support for the various nakadi-klients models.

Build

sbt compile

Install

Add the following to your build.sbt when using SBT.

libraryDependencies += "org.zalando.nakadi.client" %% "nakadi-klients-play-json" % "0.1.0"

Usage

Implicit play-json formats are can be imported by doing

import org.zalando.nakadi.client.scala.PlayJsonImplicits._

Note that the play-json formats are recursive, so you also need to provide a Format/Read/Writes for the base Event type you are dealing with.

This library also provides a generic serialization method which can be passed as a parameter to the nakadi client.publishEvents(..) call, i.e.

import org.zalando.nakadi.client.scala.model._
import org.zalando.nakadi.client.scala.{Client, ClientError}
import org.zalando.nakadi.client.utils.ClientBuilder
import org.zalando.nakadi.client.scala.NakadiSerializer

case class MyEvent(message: String)

val events = Seq(MyEvent("Dino was born, he says rawr"))

val dataChangeEvents = events.map { event =>
  DataChangeEvent(event, "my_model", DataOperation.CREATE, None)
}

val client: Client = ClientBuilder()
  .withHost("some_host")
  .withSecuredConnection(true)
  .withVerifiedSslCertificate(false)
  .withTokenProvider(Option(() => "some_token"))
  .build()

client.publishEvents("my_event_name",dataChangeEvents,NakadiSerializer.seqDataChangeEventSerializer[MyEvent])

Note that in this example, you have to provide an implicit Writes for MyEvent

Please make sure that you format the code using scalafmt. You can do this by running scalafmt in sbt before committing. See scalafmt for more info.

License

Copyright © 2016 Zalando SE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Provides play-json support for the various nakadi-klients models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages