Convert Figma logo to code with AI

akka logoalpakka-kafka

Alpakka Kafka connector - Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka.

1,416
387
1,416
108

Top Related Projects

Provides Familiar Spring Abstractions for Apache Kafka

28,317

Mirror of Apache Kafka

10,402

Change data capture for a variety of databases. Please log issues at https://issues.redhat.com/browse/DBZ.

Quick Overview

Alpakka Kafka is a reactive Kafka connector for Akka Streams, providing a robust and scalable way to integrate Apache Kafka with Akka-based applications. It offers a high-level API for consuming and producing Kafka messages within Akka Streams, enabling developers to build reactive and resilient data pipelines.

Pros

  • Seamless integration with Akka Streams, leveraging its powerful backpressure and streaming capabilities
  • High-performance and non-blocking I/O operations, suitable for building reactive systems
  • Extensive configuration options for fine-tuning Kafka consumer and producer behavior
  • Strong typing and compile-time safety, reducing runtime errors

Cons

  • Steeper learning curve for developers not familiar with Akka Streams or reactive programming concepts
  • Limited documentation compared to some other Kafka client libraries
  • Dependency on the Akka ecosystem, which may not be suitable for all projects
  • Potential complexity in error handling and recovery scenarios

Code Examples

  1. Creating a simple Kafka consumer:
import akka.kafka.scaladsl.Consumer
import akka.kafka.{ConsumerSettings, Subscriptions}
import org.apache.kafka.common.serialization.StringDeserializer

val consumerSettings = ConsumerSettings(system, new StringDeserializer, new StringDeserializer)
  .withBootstrapServers("localhost:9092")
  .withGroupId("my-group")

Consumer
  .plainSource(consumerSettings, Subscriptions.topics("my-topic"))
  .runForeach(record => println(s"Received: ${record.value()}"))
  1. Creating a simple Kafka producer:
import akka.kafka.ProducerSettings
import akka.kafka.scaladsl.Producer
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.StringSerializer

val producerSettings = ProducerSettings(system, new StringSerializer, new StringSerializer)
  .withBootstrapServers("localhost:9092")

Source(1 to 100)
  .map(i => new ProducerRecord[String, String]("my-topic", s"key-$i", s"value-$i"))
  .runWith(Producer.plainSink(producerSettings))
  1. Committing offsets manually:
Consumer
  .committableSource(consumerSettings, Subscriptions.topics("my-topic"))
  .mapAsync(1) { msg =>
    business(msg.record.value).map(_ => msg.committableOffset)
  }
  .mapAsync(1) { offset =>
    offset.commitScaladsl()
  }
  .runWith(Sink.ignore)

Getting Started

To use Alpakka Kafka in your project, add the following dependency to your build.sbt file:

libraryDependencies += "com.typesafe.akka" %% "akka-stream-kafka" % "3.0.1"

Then, import the necessary classes and create a consumer or producer as shown in the code examples above. Make sure to configure your Kafka broker settings and topic names accordingly.

Competitor Comparisons

Provides Familiar Spring Abstractions for Apache Kafka

Pros of Spring Kafka

  • Seamless integration with Spring ecosystem and dependency injection
  • Extensive documentation and large community support
  • Built-in support for common Kafka patterns and configurations

Cons of Spring Kafka

  • Steeper learning curve for developers not familiar with Spring
  • Can be more heavyweight due to Spring framework dependencies
  • Less flexibility in low-level Kafka operations compared to Alpakka Kafka

Code Comparison

Spring Kafka:

@KafkaListener(topics = "myTopic")
public void listen(String message) {
    System.out.println("Received: " + message);
}

Alpakka Kafka:

Consumer
  .plainSource(consumerSettings, Subscriptions.topics("myTopic"))
  .runForeach(record => println(s"Received: ${record.value}"))

Spring Kafka provides a more annotation-driven approach, while Alpakka Kafka offers a more reactive and stream-based API. Spring Kafka's implementation is more concise and declarative, whereas Alpakka Kafka provides greater control over the consumption process.

Both libraries offer robust Kafka integration, with Spring Kafka excelling in Spring-based applications and Alpakka Kafka shining in Akka-based, reactive systems. The choice between them often depends on the existing technology stack and specific project requirements.

28,317

Mirror of Apache Kafka

Pros of Kafka

  • Core Kafka implementation with full feature set
  • Highly scalable and distributed streaming platform
  • Extensive ecosystem and community support

Cons of Kafka

  • Steeper learning curve for beginners
  • Requires more infrastructure setup and management
  • Less integration with Akka-specific features

Code Comparison

Kafka (Java):

Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer<String, String> producer = new KafkaProducer<>(props);

Alpakka Kafka (Scala):

val producerSettings = ProducerSettings(system, new StringSerializer, new StringSerializer)
  .withBootstrapServers("localhost:9092")
val producer = producerSettings.createKafkaProducer()

Summary

Kafka is the core implementation offering a complete streaming platform with extensive features and scalability. It has a larger ecosystem but requires more setup and management. Alpakka Kafka, on the other hand, provides a more streamlined integration with Akka and Scala, making it easier to use within Akka-based applications. The code comparison shows that Alpakka Kafka offers a more concise and Akka-friendly API for working with Kafka.

10,402

Change data capture for a variety of databases. Please log issues at https://issues.redhat.com/browse/DBZ.

Pros of Debezium

  • Supports a wide range of databases (MySQL, PostgreSQL, MongoDB, etc.)
  • Provides real-time change data capture (CDC) capabilities
  • Offers built-in connectors for various data sources and sinks

Cons of Debezium

  • Steeper learning curve due to its comprehensive feature set
  • May require more configuration and setup compared to Alpakka Kafka

Code Comparison

Debezium (using Debezium Engine API):

DebeziumEngine<ChangeEvent<String, String>> engine = DebeziumEngine.create(Json.class)
    .using(props)
    .notifying(record -> {
        System.out.println(record);
    }).build();
engine.run();

Alpakka Kafka (using Akka Streams):

val kafkaConsumerSettings = ConsumerSettings(system, new StringDeserializer, new StringDeserializer)
  .withBootstrapServers("localhost:9092")
  .withGroupId("group1")

Consumer.plainSource(kafkaConsumerSettings, Subscriptions.topics("topic1"))
  .runForeach(println)

Both projects offer robust solutions for working with Kafka, but they serve different purposes. Alpakka Kafka focuses on integrating Kafka with Akka Streams, providing a reactive and stream-based approach. Debezium, on the other hand, specializes in change data capture from various databases, offering a more comprehensive solution for data integration and real-time event streaming.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Alpakka Kafka gh-actions-badge

Systems don't come alone. In the modern world of microservices and cloud deployment, new components must interact with legacy systems, making integration an important key to success. Reactive Streams give us a technology-independent tool to let these heterogeneous systems communicate without overwhelming each other.

The Alpakka project is an open source initiative to implement stream-aware, reactive, integration pipelines for Java and Scala. It is built on top of Akka Streams, and has been designed from the ground up to understand streaming natively and provide a DSL for reactive and stream-oriented programming, with built-in support for backpressure. Akka Streams is a Reactive Streams and JDK 9+ java.util.concurrent.Flow-compliant implementation and therefore fully interoperable with other implementations.

This repository contains the sources for the Alpakka Kafka connector. Which lets you connect Apache Kafka to Akka Streams. It was formerly known as Akka Streams Kafka and even Reactive Kafka.

Akka Stream connectors to other technologies are listed in the Alpakka repository.

Documentation

To keep up with the latest Alpakka releases check out Alpakka releases and Alpakka Kafka releases.

Community

You can join these groups and chats to discuss and ask Akka and Alpakka related questions:

In addition to that, you may enjoy following:

The Kafka connector was originally created as Reactive Kafka by SoftwareMill logo.

Contributing

The Akka family of projects is managed by teams at Lightbend with help from the community.

Contributions are very welcome! Lightbend appreciates community contributions by both those new to Alpakka and those more experienced.

Alpakka depends on the community to keep up with the ever-growing number of technologies with which to integrate. Please step up and share the successful Akka Stream integrations you implement with the Alpakka community.

If you find an issue that you'd like to see fixed, the quickest way to make that happen is to implement the fix and submit a pull request.

Refer to the CONTRIBUTING.md file for more details about the workflow, and general hints on how to prepare your pull request.

You can also ask for clarifications or guidance in GitHub issues directly.

Caveat Emptor

Alpakka components are not always binary compatible between releases. API changes that are not backward compatible might be introduced as we refine and simplify based on your feedback. A module may be dropped in any release without prior deprecation.

License

Akka is licensed under the Business Source License 1.1, please see the Akka License FAQ.

Tests and documentation are under a separate license, see the LICENSE file in each documentation and test root directory for details.