Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API change proposal #89

Open
vitold opened this issue Feb 6, 2019 · 4 comments
Open

API change proposal #89

vitold opened this issue Feb 6, 2019 · 4 comments
Milestone

Comments

@vitold
Copy link

vitold commented Feb 6, 2019

As a part of a new project, we are considering to use kanadi as a driver for streaming from nakadi.
Going through the source code I found some inconvenient parts which put some low-level responsibility on the client:
1)

 val callback = EventCallback.successAlways[SomeEvent] { eventCallbackData =>
    eventCallbackData.subscriptionEvent.events.getOrElse(List.empty).foreach{ 
      case e: Event.Business[SomeEvent] =>
        ..
      case e: Event.DataChange[_] =>
        ...
      case e: Event.Undefined[_] =>
        ...
    }
  }

I suggest to refactor it to:

val callback = EventCallback.successAlways[Event.Business[SomeEvent]] { // Or other message type
  events => // which alredy has type List[Event.Business[SomeEvent]]
    ...
  }
}

The reason for this is the api of nakadi do not allow you to have several message types in the same event type, so this pattern matching becomes an unnecessary boilerplate every time when you creating the event batch handler.

2)
Change the type of SubscriptionEvent.events from Option[List[Event[T]]] to NonEmptyList[Event[T]]
As a user of the driver, you do not expect to receive an empty batch. And in case of an error, it should be reported internally in the driver.

@i-am-the-slime
Copy link

I realised yesterday that it is possible to have subscriptions for multiple event types. I am not sure that this allows for different kinds of events. Maybe it makes sense to keep the old API and just add convenience methods on top for the 99% case of always the same event type.

@vitold
Copy link
Author

vitold commented Feb 21, 2019

@i-am-the-slime Api extension even better. For backward compatibility for example.

@mdedetrich
Copy link
Collaborator

Sorry for the late response guys, I missed my github notifications

I am definitely up for making a release of Kanadi that fixes the API, there are quite a few historical mistakes. @i-am-the-slime has a point though, you can technically subscribe to multiple event types which have different structures (i.e. undefined vs data vs business)

The only issue is that I am currently maintaining 3 branches (yay for binary compatibility!) so I need to think about how to approach this.

@mdedetrich
Copy link
Collaborator

@vitold But yeah, a PR to add an extra method for this case is always welcome, that way its backwards compatible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants