README.md in phobos_db_checkpoint-3.3.0 vs README.md in phobos_db_checkpoint-3.4.0

- old
+ new

@@ -1,7 +1,9 @@ -![CircleCI](https://circleci.com/gh/klarna/phobos_db_checkpoint/tree/master.svg?style=shield&circle-token=a69fda09f130a862b69f6a7e8be834f884829ccd) -[![Coverage Status](https://coveralls.io/repos/github/klarna/phobos_db_checkpoint/badge.svg?branch=master)](https://coveralls.io/github/klarna/phobos_db_checkpoint?branch=master) +[![Build Status](https://travis-ci.org/klarna/phobos_db_checkpoint.svg?branch=travis)](https://travis-ci.org/klarna/phobos_db_checkpoint) +[![Maintainability](https://api.codeclimate.com/v1/badges/6f508f2515a418568bd8/maintainability)](https://codeclimate.com/github/klarna/phobos_db_checkpoint/maintainability) +[![Test Coverage](https://api.codeclimate.com/v1/badges/6f508f2515a418568bd8/test_coverage)](https://codeclimate.com/github/klarna/phobos_db_checkpoint/test_coverage) +[![Chat with us on Discord](https://discordapp.com/api/guilds/379938130326847488/widget.png)](https://discord.gg/rfMUBVD) # Phobos DB Checkpoint Phobos DB Checkpoint is a plugin to [Phobos](https://github.com/klarna/phobos) and is meant as a drop in replacement to `Phobos::Handler`, extending it with the following features: * Persists your Kafka events to an active record compatible database @@ -116,30 +118,27 @@ ack(my_event['id'], Time.now) end end ``` -If your handler returns anything different than an __ack__ it won't be saved to the database. +In case your handler returns anything different from an __ack__ it won't be saved to the database. Note that the `PhobosDBCheckpoint::Handler` will automatically skip already handled events (i.e. duplicate Kafka messages). #### <a name="payload"></a> Payload PhobosDBCheckpoint assumes that the payload received from Phobos is in a JSON format. This means that if your payload is in any other format, for example Avro binary, you need to convert/decode it to JSON. -To achieve this you can override the `#before_consume` method of the handler: +To achieve this you can compose a new handler with `PhobosDBCheckpoint::Handler` using the `#around_consume` method: ```ruby class MyHandler include PhobosDBCheckpoint::Handler # <-- setup @avro before - def before_consume(payload) - @avro.decode(payload) - end - - def consume(payload, metadata) - # <-- consume your stuff with the decoded payload + def around_consume(payload, metadata) + decoded_payload = @avro.decode(payload) + super(decoded_payload, metadata) end end ``` #### <a name="failures"></a> Failures