Book Image

Apache Kafka 1.0 Cookbook

By : Alexey Zinoviev, Raúl Estrada
Book Image

Apache Kafka 1.0 Cookbook

By: Alexey Zinoviev, Raúl Estrada

Overview of this book

Apache Kafka provides a unified, high-throughput, low-latency platform to handle real-time data feeds. This book will show you how to use Kafka efficiently, and contains practical solutions to the common problems that developers and administrators usually face while working with it. This practical guide contains easy-to-follow recipes to help you set up, configure, and use Apache Kafka in the best possible manner. You will use Apache Kafka Consumers and Producers to build effective real-time streaming applications. The book covers the recently released Kafka version 1.0, the Confluent Platform and Kafka Streams. The programming aspect covered in the book will teach you how to perform important tasks such as message validation, enrichment and composition.Recipes focusing on optimizing the performance of your Kafka cluster, and integrate Kafka with a variety of third-party tools such as Apache Hadoop, Apache Spark, and Elasticsearch will help ease your day to day collaboration with Kafka greatly. Finally, we cover tasks related to monitoring and securing your Apache Kafka cluster using tools such as Ganglia and Graphite. If you're looking to become the go-to person in your organization when it comes to working with Apache Kafka, this book is the only resource you need to have.
Table of Contents (18 chapters)
Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Dedication
Preface

Preface

Since 2011, Kafka's growth has exploded. More than one-third of all Fortune 500 companies use Apache Kafka. These companies include the top 10 travel companies, 7 of the top 10 banks, 8 of the top 10 insurance companies, and 9 of the top 10 telecom companies.

LinkedIn, Uber, Twitter, Spotify, Paypal, and Netflix process with Apache Kafka, each one with a total of four-comma (1,000,000,000,000) messages in a single day.

Nowadays, Apache Kafka is used for real-time data streaming, to collect data, or to do real-time data analyses. In other contexts, Kafka is used in microservice architectures to improve durability. It can also be used to feed events to Complex Event Processing (CEP) architectures and IoT automation systems.

Today we live in the middle of a war, a streaming war. Several competitors (Kafka Streams, Spark Streaming, Akka Streaming, Apache Flink, Apache Storm, Apache Beam, Amazon Kinesis, and so on) are immersed in a competition where there are many factors to evaluate, but mainly the winner is the one with the best performance.

Much of the current adoption of Apache Kafka is due to its ease of use. Kafka is easy to implement, easy to learn, and easy to maintain. Unlike most of its competitors, the learning curve is not so steep.

This book is practical; it is focused on hands-on recipes and it isn't just stop at theoretical or architectural explanations about Apache Kafka. This book is a cookbook, a compendium of practical recipes that are solutions to everyday problems faced in the implementation of a streaming architecture with Apache Kafka. The first part of the book is about programming, and the second part is about Apache Kafka administration.

What this book covers

Chapter 1, Configuring Kafka, explains the basic recipes used to get started with Apache Kafka. It discusses how to install, configure, and run Kafka. It also discusses how to do basic operations with a Kafka broker.

Chapter 2, Kafka Clusters, covers how to make three types of clusters: single-node single-broker cluster, single-node multiple-broker cluster, and multiple-node multiple-broker cluster.

Chapter 3, Message Validation, in this chapter having an enterprise service bus, one of the tasks is related to data validation, this is filtering some events from an input message stream. This chapter is about the programming of this validation.

Chapter 4, Message Enrichment, details how the next task of an enterprise service bus is related to message enrichment, which means having an individual message, obtaining additional information, and incorporating it into the message stream.

Chapter 5, The Confluent Platform, shows how to operate and monitor a Kafka system with the Confluent Platform. It also explains how to use the Schema Registry, the Kafka REST Proxy, and Kafka Connect.

Chapter 6, Kafka Streams, explains how to obtain information about a group of messages (a message stream) and additional information such as aggregation and composition of messages using Kafka Streams.

Chapter 7, Managing Kafka, talks about the command-line tools developed by the authors of Kafka to make a sysadmin team's life easier when debugging, testing, and running a Kafka cluster.

Chapter 8, Operating Kafka, explains the different operations that can be done on a Kafka cluster. These tools cannot be used daily, but they help the DevOps team manage Kafka clusters.

Chapter 9, Monitoring and Security, has a first half that talks about various statistics, how they are exposed, and how to monitor them with tools such as Graphite and Ganglia. Its second part is about security—in a nutshell, how to implement SSL authentication, SASL/Kerberos authentication, and SASL/plain authentication.

Chapter 10, Third-Party Tool Integration, talks about other real-time data processing tools and how to use Apache Kafka to make a data processing pipeline with them. Tools such as Hadoop, Flume, Gobblin, Elastic, Logstash, Spark, Storm, Solr, Akka, Cassandra, Mesos, and Beam are covered in this chapter.

What you need for this book

The reader should have some experience in programming with Java and some experience in Linux/Unix operating systems.

The minimum configuration needed to execute the recipes in this book is: Intel ® Core i3 processor, 4 GB RAM, and 128 GB of disks. It is recommended to use Linux or Mac OS. Windows is not fully supported.

Who this book is for

This book is for software developers, data architects, and data engineers looking for practical Kafka recipes.

The first half of this cookbook is about programming; this is introductory material for those with no previous knowledge of Apache Kafka. As the book progresses, the difficulty level increases.

The second half of this cookbook is about configuration; this is advanced material for those who want to improve existing Apache Kafka systems or want to better administer current Kafka deployments.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it…, How it works…, There's more…, and See also). To give clear instructions on how to complete a recipe, we use these sections as follows.

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Finally, run the apt-get update to install the Confluent Platform."

A block of code is set as follows:

consumer.interceptor.classes=io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor 
producer.interceptor.classes=io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor 

Any command-line input or output is written as follows:

> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic SNSBTopic

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "From Kafka Connect, click on the SINKS button and then on the New sink button."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors .

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account. Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Apache-Kafka-1-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/ApacheKafka1Cookbook_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.