{"id":383279,"date":"2024-06-29T04:48:55","date_gmt":"2024-06-29T04:48:55","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=383279"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=383279","title":{"rendered":"<span>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 Apache Cassandra. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441 \u0441 Cassandra \u0438 Kafka<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf1\/600\/062\/cf1600062b1b8ebcd8467f142e24885f.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf1\/600\/062\/cf1600062b1b8ebcd8467f142e24885f.png\"\/><\/figure>\n<div class=\"persona\" persona=\"true\"><img decoding=\"async\" persona=\"true\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/d12\/184\/85b\/d1218485b3c01806815f720662513621.jpg\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d12\/184\/85b\/d1218485b3c01806815f720662513621.jpg\" data-blurred=\"true\"\/><\/p>\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0420\u0443\u0441\u0442\u0435\u043c \u0413\u0430\u043b\u0438\u0435\u0432<\/h5>\n<p>IBM Senior DevOps Engineer &amp; Integration Architect  <\/p>\n<\/div>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Apache Cassandra \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Apache Kafka.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Reservation Service. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0435\u0440\u0438\u044e \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439 \u043f\u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0447\u0442\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Cassandra \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0443\u0436\u0431\u044b \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u00abCassandra: \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax\u00bb. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043b\u0443\u0436\u0431\u044b \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/github.com\/jeffreyscarpenter\/reservation-service\">\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub<\/a>.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/be7\/3f1\/c11\/be73f1c11922d8ae38f2e95dc6dd4d34.png\" alt=\"\" title=\"\" width=\"1362\" height=\"675\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/be7\/3f1\/c11\/be73f1c11922d8ae38f2e95dc6dd4d34.png\"\/><\/figure>\n<p>\u0421\u043b\u0443\u0436\u0431\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/df2\/4e3\/b2b\/df24e3b2b6d75d1c6a0cb9a38b7eeffa.png\" alt=\"\" title=\"\" width=\"1600\" height=\"1025\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/df2\/4e3\/b2b\/df24e3b2b6d75d1c6a0cb9a38b7eeffa.png\"\/><\/figure>\n<p>Cassandra \u0438 Kafka \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430\u0445, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435. \u0412 \u044d\u0442\u043e\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0441\u043b\u0443\u0436\u0431\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 Cassandra \u0441\u043b\u0443\u0436\u0431\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u043f\u0438\u043a reservation \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 Kafka.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/202\/be7\/c00\/202be7c0053919f09c8a309de6209fd5.png\" alt=\"\" title=\"\" width=\"1104\" height=\"500\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/202\/be7\/c00\/202be7c0053919f09c8a309de6209fd5.png\"\/><\/figure>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u0443\u0436\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043f\u0438\u043a reservation \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0443\u0436\u0431\u0430 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0434\u0430\u0442\u044b \u043a\u0430\u043a \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0438\u043b\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043b\u0443\u0436\u0431\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0441 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u0433\u043e\u0441\u0442\u044e \u0437\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u041a\u0430\u0441\u0441\u0430\u043d\u0434\u0440\u0430 \u0438 \u041a\u0430\u0444\u043a\u0430 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u043b\u0443\u0436\u0431\u044b \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p><strong><br \/><\/strong>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 Reservation Service \u0441 GitHub \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0435\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439:<\/p>\n<p><code>git clone -b kafka<\/code> <a href=\"https:\/\/github.com\/jeffreyscarpenter\/reservation-service\"><u>https:\/\/github.com\/jeffreyscarpenter\/reservation-service<\/u><\/p>\n<p><\/a>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>reservation_service<\/code>.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0445\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <code>reservation-service\/src\/main\/resources\/reservation.cql<\/code>:<\/p>\n<pre><code class=\"java\">\/*  * Copyright (C) 2016-2020 Jeff Carpenter  *\/  \/* This file contains a slightly modified version of the \"reservation\" keyspace and table definitions  * for the example defined in Chapter 5 of Cassandra: The Definitive Guide, 2nd and 3nd Editions.  * The changes are to facilitate development exercises.  *\/  CREATE KEYSPACE reservation     WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};  CREATE TABLE reservation.reservations_by_hotel_date (     hotel_id text,     start_date date,     end_date date,     room_number smallint,     confirm_number text,     guest_id uuid,     PRIMARY KEY ((hotel_id, start_date), room_number) );  CREATE TABLE reservation.reservations_by_confirmation (     confirm_number text PRIMARY KEY,     hotel_id text,     start_date date,     end_date date,     room_number smallint,     guest_id uuid );  \/*  The following tables are provided for completeness with the book text, but they are not used in the current  implementation of the Reservation Service  *\/  CREATE TABLE reservation.reservations_by_guest (     guest_last_name text,     hotel_id text,     start_date date,     end_date date,     room_number smallint,     confirm_number text,     guest_id uuid,     PRIMARY KEY ((guest_last_name), hotel_id) );  CREATE TYPE reservation.address (     street text,     city text,     state_or_province text,     postal_code text,     country text );  CREATE TABLE reservation.guests (     guest_id uuid PRIMARY KEY,     first_name text,     last_name text,     title text,     emails set&lt;text>,     phone_numbers list&lt;text>,     addresses map&lt;text, frozen&lt;address>> );<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax Java \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Kafka \u043f\u043e \u043f\u0443\u0442\u0438 <code>reservation-service\/pom.xml<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?> &lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"> &lt;modelVersion>4.0.0&lt;\/modelVersion>  &lt;groupId>com.cassandraguide&lt;\/groupId> &lt;artifactId>reservation-service&lt;\/artifactId> &lt;version>1.0.0&lt;\/version> &lt;packaging>jar&lt;\/packaging>  &lt;name>reservation-service&lt;\/name> &lt;description>Demo service using Cassandra driver and Spring Boot&lt;\/description>  &lt;parent> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-parent&lt;\/artifactId> &lt;version>2.2.6.RELEASE&lt;\/version> &lt;relativePath \/> &lt;\/parent>  &lt;properties> &lt;java.version>11&lt;\/java.version> &lt;swagger.version>2.9.2&lt;\/swagger.version> &lt;junit-jupiter.version>5.4.2&lt;\/junit-jupiter.version> &lt;junit-platform.version>1.7.0-M1&lt;\/junit-platform.version> &lt;oss-java-driver.version>4.5.1&lt;\/oss-java-driver.version> &lt;kafka-client.version>2.5.0&lt;\/kafka-client.version> &lt;testcontainers.version>1.14.1&lt;\/testcontainers.version>  &lt;version.maven.plugin.compiler>3.8.0&lt;\/version.maven.plugin.compiler> &lt;project.build.sourceEncoding>UTF-8&lt;\/project.build.sourceEncoding> &lt;start-class>dev.cassandraguide.ReservationServiceApp&lt;\/start-class> &lt;dockerfile-maven-version>1.4.13&lt;\/dockerfile-maven-version>  &lt;\/properties>  &lt;dependencies>  &lt;!-- Create a RESTFul Service --> &lt;dependency> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-web&lt;\/artifactId> &lt;\/dependency>  &lt;!-- Document for REST Service --> &lt;dependency> &lt;groupId>io.springfox&lt;\/groupId> &lt;artifactId>springfox-swagger2&lt;\/artifactId> &lt;version>${swagger.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>io.springfox&lt;\/groupId> &lt;artifactId>springfox-swagger-ui&lt;\/artifactId> &lt;version>${swagger.version}&lt;\/version> &lt;\/dependency>  &lt;!-- Cassandra Driver --> &lt;dependency> &lt;groupId>com.datastax.oss&lt;\/groupId> &lt;artifactId>java-driver-core&lt;\/artifactId> &lt;version>${oss-java-driver.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>com.datastax.oss&lt;\/groupId> &lt;artifactId>java-driver-query-builder&lt;\/artifactId> &lt;version>${oss-java-driver.version}&lt;\/version> &lt;\/dependency>  &lt;dependency> &lt;groupId>org.apache.kafka&lt;\/groupId> &lt;artifactId>kafka-clients&lt;\/artifactId> &lt;version>${kafka-client.version}&lt;\/version> &lt;\/dependency>  &lt;dependency> &lt;groupId>org.apache.commons&lt;\/groupId> &lt;artifactId>commons-lang3&lt;\/artifactId> &lt;\/dependency> &lt;!-- Provides JSON serialization\/deserialization for date\/time types --> &lt;dependency> &lt;groupId>com.fasterxml.jackson.datatype&lt;\/groupId> &lt;artifactId>jackson-datatype-jsr310&lt;\/artifactId> &lt;\/dependency>  &lt;!-- Tests --> &lt;dependency> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-test&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;exclusions> &lt;exclusion> &lt;groupId>junit&lt;\/groupId> &lt;artifactId>junit&lt;\/artifactId> &lt;\/exclusion> &lt;\/exclusions> &lt;\/dependency> &lt;!-- Junit 5 --> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-api&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-engine&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-params&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-engine&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-launcher&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-runner&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-console-standalone&lt;\/artifactId> &lt;version>${junit-platform.version}&lt;\/version> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;!-- Test against Docker Containers --> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>cassandra&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>testcontainers&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>kafka&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;!-- Add driver keys to spring-boot config file --> &lt;dependency>            &lt;groupId>org.springframework.boot&lt;\/groupId>            &lt;artifactId>spring-boot-configuration-processor&lt;\/artifactId>            &lt;optional>true&lt;\/optional>         &lt;\/dependency>          &lt;\/dependencies>  &lt;build> &lt;plugins> &lt;plugin> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-maven-plugin&lt;\/artifactId> &lt;configuration> &lt;fork>true&lt;\/fork> &lt;mainClass>${start-class}&lt;\/mainClass> &lt;\/configuration> &lt;executions> &lt;execution> &lt;goals> &lt;goal>repackage&lt;\/goal> &lt;\/goals> &lt;\/execution> &lt;\/executions> &lt;\/plugin>             &lt;plugin>                 &lt;groupId>org.apache.maven.plugins&lt;\/groupId>                 &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>                 &lt;configuration>                     &lt;source>${java.version}&lt;\/source>                     &lt;target>${java.version}&lt;\/target> &lt;\/configuration>             &lt;\/plugin>  &lt;plugin> &lt;groupId>com.spotify&lt;\/groupId> &lt;artifactId>dockerfile-maven-plugin&lt;\/artifactId> &lt;version>${dockerfile-maven-version}&lt;\/version> &lt;configuration> &lt;repository>reservation-service&lt;\/repository> &lt;tag>${project.version}&lt;\/tag> &lt;buildArgs> &lt;JAR_FILE>${project.build.finalName}.jar&lt;\/JAR_FILE> &lt;\/buildArgs> &lt;\/configuration> &lt;\/plugin>         &lt;\/plugins> &lt;\/build>  &lt;\/project> <\/code><\/pre>\n<p>\u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c:<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0432 HTTP API, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 Cassandra \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0432 \u0442\u0435\u043c\u0435 Kafka r<code>eservation-service\/src\/main\/java\/dev\/cassandraguide\/model\/Reservation.java<\/code>:<\/p>\n<pre><code class=\"java\">\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * 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.  *\/ package dev.cassandraguide.model;  import java.io.Serializable; import java.time.LocalDate; import java.util.UUID;  \/**  * Entity working with Reservation on Cassandra.  *  * @author Jeff Carpenter  *\/ public class Reservation implements Serializable {      \/** Serial. *\/     private static final long serialVersionUID = -3392237616280919281L;          \/** Hotel identifier, as Text not UUID (for simplicity). *\/     private String hotelId;          \/** Formated as YYYY-MM-DD in interfaces. *\/     private LocalDate startDate;          \/** Formated as YYYY-MM-DD in interfaces. *\/     private LocalDate endDate;          \/** Room number. *\/     private short roomNumber;          \/** UUID. *\/     private UUID guestId;          \/** Confirmation for this Reservation. *\/     private String confirmationNumber;          \/**      * Default constructor      *\/     public Reservation() {     }          \/**      * Default constructor      *\/     public Reservation(ReservationRequest form) {         setStartDate(form.getStartDate());         setEndDate(form.getEndDate());         setHotelId(form.getHotelId());         setGuestId(form.getGuestId());         setRoomNumber(form.getRoomNumber());     }          \/**      * Default constructor      *\/     public Reservation(ReservationRequest form, String confirmationNumber) {         this(form);         this.confirmationNumber = confirmationNumber;     }      \/**      * Getter accessor for attribute 'hotelId'.      *      * @return      *       current value of 'hotelId'      *\/     public String getHotelId() {         return hotelId;     }      \/**      * Setter accessor for attribute 'hotelId'.      * @param hotelId      *      new value for 'hotelId '      *\/     public void setHotelId(String hotelId) {         this.hotelId = hotelId;     }      \/**      * Getter accessor for attribute 'startDate'.      *      * @return      *       current value of 'startDate'      *\/     public LocalDate getStartDate() {         return startDate;     }      \/**      * Setter accessor for attribute 'startDate'.      * @param startDate      *      new value for 'startDate '      *\/     public void setStartDate(LocalDate startDate) {         this.startDate = startDate;     }      \/**      * Getter accessor for attribute 'endDate'.      *      * @return      *       current value of 'endDate'      *\/     public LocalDate getEndDate() {         return endDate;     }      \/**      * Setter accessor for attribute 'endDate'.      * @param endDate      *      new value for 'endDate '      *\/     public void setEndDate(LocalDate endDate) {         this.endDate = endDate;     }      \/**      * Getter accessor for attribute 'roomNumber'.      *      * @return      *       current value of 'roomNumber'      *\/     public short getRoomNumber() {         return roomNumber;     }      \/**      * Setter accessor for attribute 'roomNumber'.      * @param roomNumber      *      new value for 'roomNumber '      *\/     public void setRoomNumber(short roomNumber) {         this.roomNumber = roomNumber;     }      \/**      * Getter accessor for attribute 'guestId'.      *      * @return      *       current value of 'guestId'      *\/     public UUID getGuestId() {         return guestId;     }      \/**      * Setter accessor for attribute 'guestId'.      * @param guestId      *      new value for 'guestId '      *\/     public void setGuestId(UUID guestId) {         this.guestId = guestId;     }      \/**      * Getter accessor for attribute 'confirmationNumber'.      *      * @return      *       current value of 'confirmationNumber'      *\/     public String getConfirmationNumber() {         return confirmationNumber;     }      \/**      * Setter accessor for attribute 'confirmationNumber'.      * @param confirmationNumber      * new value for 'confirmationNumber '      *\/     public void setConfirmationNumber(String confirmationNumber) {         this.confirmationNumber = confirmationNumber;     }          \/** {@inheritDoc} *\/     @Override     public String toString() {         return \"Confirmation Number = \" + confirmationNumber +                 \", Hotel ID: \" + getHotelId() +                 \", Start Date = \" + getStartDate() +                 \", End Date = \" + getEndDate() +                 \", Room Number = \" + getRoomNumber() +                 \", Guest ID = \" + getGuestId();     } }<\/code><\/pre>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0433\u0434\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b <code>reservation-service\/src\/main\/java\/dev\/cassandraguide\/repository\/ReservationRepository.java<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>ReservationRepository.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * 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.  *\/ package dev.cassandraguide.repository;  import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createType; import static com.datastax.oss.driver.api.querybuilder.relation.Relation.column;  import java.time.LocalDate; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors;  import javax.annotation.PreDestroy;  import com.fasterxml.jackson.core.JsonProcessingException; import dev.cassandraguide.model.Reservation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Profile; import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository;  import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.cql.BatchStatement; import com.datastax.oss.driver.api.core.cql.BoundStatement; import com.datastax.oss.driver.api.core.cql.DefaultBatchType; import com.datastax.oss.driver.api.core.cql.PreparedStatement; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.core.type.DataTypes; import com.datastax.oss.driver.api.core.type.UserDefinedType; import com.datastax.oss.driver.api.querybuilder.QueryBuilder;  \/\/ TODO: Review imports for publishing to Kafka import org.apache.kafka.clients.producer.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;  \/**  * The goal of this project is to provide a minimally functional implementation of a microservice   * that uses Apache Cassandra for its data storage. The reservation service is implemented as a   * RESTful service using Spring Boot.  *  * @author Jeff Carpenter, Cedrick Lunven  *\/ @Repository @Profile(\"!unit-test\") \/\/ When I do some 'unit-test' no connectivity to DB public class ReservationRepository {      \/** Logger for the class. *\/     private static final Logger logger = LoggerFactory.getLogger(ReservationRepository.class);          \/\/ Reservation Schema Constants     public static final CqlIdentifier TYPE_ADDRESS               = CqlIdentifier.fromCql(\"address\");     public static final CqlIdentifier TABLE_RESERVATION_BY_HOTEL_DATE =             CqlIdentifier.fromCql(\"reservations_by_hotel_date\");     public static final CqlIdentifier TABLE_RESERVATION_BY_CONFI = CqlIdentifier.fromCql(\"reservations_by_confirmation\");     public static final CqlIdentifier TABLE_RESERVATION_BY_GUEST = CqlIdentifier.fromCql(\"reservations_by_guest\");     public static final CqlIdentifier TABLE_GUESTS               = CqlIdentifier.fromCql(\"guests\");     public static final CqlIdentifier STREET                     = CqlIdentifier.fromCql(\"street\");     public static final CqlIdentifier CITY                       = CqlIdentifier.fromCql(\"city\");     public static final CqlIdentifier STATE_PROVINCE             = CqlIdentifier.fromCql(\"state_or_province\");     public static final CqlIdentifier POSTAL_CODE                = CqlIdentifier.fromCql(\"postal_code\");     public static final CqlIdentifier COUNTRY                    = CqlIdentifier.fromCql(\"country\");     public static final CqlIdentifier HOTEL_ID                   = CqlIdentifier.fromCql(\"hotel_id\");     public static final CqlIdentifier START_DATE                 = CqlIdentifier.fromCql(\"start_date\");     public static final CqlIdentifier END_DATE                   = CqlIdentifier.fromCql(\"end_date\");     public static final CqlIdentifier ROOM_NUMBER                = CqlIdentifier.fromCql(\"room_number\");     public static final CqlIdentifier CONFIRM_NUMBER             = CqlIdentifier.fromCql(\"confirm_number\");     public static final CqlIdentifier GUEST_ID                   = CqlIdentifier.fromCql(\"guest_id\");     public static final CqlIdentifier GUEST_LAST_NAME            = CqlIdentifier.fromCql(\"guest_last_name\");     public static final CqlIdentifier FIRSTNAME                  = CqlIdentifier.fromCql(\"first_name\");     public static final CqlIdentifier LASTNAME                   = CqlIdentifier.fromCql(\"last_name\");     public static final CqlIdentifier TITLE                      = CqlIdentifier.fromCql(\"title\");     public static final CqlIdentifier EMAILS                     = CqlIdentifier.fromCql(\"emails\");     public static final CqlIdentifier PHONE_NUMBERS              = CqlIdentifier.fromCql(\"phone_numbers\");     public static final CqlIdentifier ADDRESSES                  = CqlIdentifier.fromCql(\"addresses\");          private PreparedStatement psExistReservation;     private PreparedStatement psFindReservation;     private PreparedStatement psInsertReservationByHotelDate;     private PreparedStatement psInsertReservationByConfirmation;     private PreparedStatement psDeleteReservationByHotelDate;     private PreparedStatement psDeleteReservationByConfirmation;     private PreparedStatement psSearchReservation;          \/** CqlSession holding metadata to interact with Cassandra. *\/     private CqlSession     cqlSession;     private CqlIdentifier  keyspaceName;      \/\/ TODO: Review variables used for publishing to Kafka     \/** KafkaProducer for publishing messages to Kafka. *\/     private KafkaProducer&lt;String, String> kafkaProducer;     private String kafkaTopicName;     private ObjectMapper objectMapper;          \/** External Initialization. *\/     public ReservationRepository(             @NonNull CqlSession cqlSession,              @Qualifier(\"keyspace\") @NonNull CqlIdentifier keyspaceName,             @NonNull KafkaProducer&lt;String, String> kafkaProducer,             @NonNull String kafkaTopicName) {         this.cqlSession   = cqlSession;         this.keyspaceName = keyspaceName;          \/\/ TODO: Review initialization of objects needed for publishing to Kafka         this.kafkaProducer = kafkaProducer;         this.kafkaTopicName = kafkaTopicName;          objectMapper = new ObjectMapper();         objectMapper.registerModule(new JavaTimeModule());         objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);         objectMapper.enable(SerializationFeature.INDENT_OUTPUT);          \/\/ Will create tables (if they do not exist)         createReservationTables();                  \/\/ Prepare Statements of reservation         prepareStatements();         logger.info(\"Application initialized.\");     }          \/**      * CqlSession is a stateful object handling TCP connections to nodes in the cluster.      * This operation properly closes sockets when the application is stopped      *\/     @PreDestroy     public void cleanup() {         if (null != cqlSession) {             cqlSession.close();             logger.info(\"+ CqlSession has been successfully closed\");         }     }          \/**      * Testing existence is useful for building correct semantics in the RESTful API. To evaluate existence find the      * table where confirmation number is partition key which is reservations_by_confirmation      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      true if the reservation exists, false if it does not      *\/     public boolean exists(String confirmationNumber) {         return cqlSession.execute(psExistReservation.bind(confirmationNumber))                          .getAvailableWithoutFetching() > 0;     }          \/**      * Similar to exists() but maps and parses results.      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      reservation if present or empty      *\/     @NonNull     public Optional&lt;Reservation> findByConfirmationNumber(@NonNull String confirmationNumber) {                  ResultSet resultSet = cqlSession.execute(psFindReservation.bind(confirmationNumber));                  \/\/ Hint: an empty result might not be an error as this method is sometimes used to check whether a         \/\/ reservation with this confirmation number exists         Row row = resultSet.one();         if (row == null) {             logger.debug(\"Unable to load reservation with confirmation number: \" + confirmationNumber);             return Optional.empty();         }                  \/\/ Hint: If there is a result, create a new reservation object and set the values         \/\/ Bonus: factor the logic to extract a reservation from a row into a separate method         \/\/ (you will reuse it again later in getAllReservations())         return Optional.of(mapRowToReservation(row));     }          \/**      * Create new entry in multiple tables for this reservation.      *      * @param reservation      *      current reservation object      * @return      *      confirmation number for the reservation      *            *\/      public String upsert(Reservation reservation) {         Objects.requireNonNull(reservation);         if (null == reservation.getConfirmationNumber()) {             \/\/ Generating a new reservation number if none has been provided             reservation.setConfirmationNumber(UUID.randomUUID().toString());         }         \/\/ Insert into 'reservations_by_hotel_date'         BoundStatement bsInsertReservationByHotel =                  psInsertReservationByHotelDate.bind(reservation.getHotelId(), reservation.getStartDate(),                         reservation.getEndDate(), reservation.getRoomNumber(), reservation.getConfirmationNumber(),                         reservation.getGuestId());         \/\/ Insert into 'reservations_by_confirmation'         BoundStatement bsInsertReservationByConfirmation =                  psInsertReservationByConfirmation.bind(reservation.getConfirmationNumber(), reservation.getHotelId(),                         reservation.getStartDate(), reservation.getEndDate(), reservation.getRoomNumber(),                         reservation.getGuestId());         BatchStatement batchInsertReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsInsertReservationByHotel)                     .addStatement(bsInsertReservationByConfirmation)                     .build();         cqlSession.execute(batchInsertReservation);          \/\/ TODO: Publish message to Kafka containing reservation          try {              String reservationJson = objectMapper.writeValueAsString(reservation);              \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)              \/\/ with the reservation confirmation number as the key, and the JSON string as the value              ProducerRecord&lt;String, String> record = null;              kafkaProducer.send(record);          } catch (Exception e) {              logger.warn(\"Error publishing reservation message to Kafka: {}\", e);          }          return reservation.getConfirmationNumber();     }      \/**      * We pick 'reservations_by_confirmation' table to list reservations      * BUT we could have used 'reservations_by_hotel_date' (as no key provided in request)      *        * @return      *      list containing all reservations      *\/     public List&lt;Reservation> findAll() {         return cqlSession.execute(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all().build())                   .all()                          \/\/ no paging we retrieve all objects                   .stream()                       \/\/ because we are good people                   .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                   .collect(Collectors.toList());  \/\/ Back to list objects     }            \/**      * Deleting a reservation.      *      * @param confirmationNumber      *      unique identifier for confirmation.      *\/     public boolean delete(String confirmationNumber) {          \/\/ Retrieving entire reservation in order to obtain the attributes we will need to delete from         \/\/ reservations_by_hotel_date table         Optional&lt;Reservation> reservationToDelete = this.findByConfirmationNumber(confirmationNumber);          if (reservationToDelete.isPresent()) {              \/\/ Delete from 'reservations_by_hotel_date'             Reservation reservation = reservationToDelete.get();             BoundStatement bsDeleteReservationByHotelDate =                     psDeleteReservationByHotelDate.bind(reservation.getHotelId(),                             reservation.getStartDate(), reservation.getRoomNumber());              \/\/ Delete from 'reservations_by_confirmation'             BoundStatement bsDeleteReservationByConfirmation =                     psDeleteReservationByConfirmation.bind(confirmationNumber);              BatchStatement batchDeleteReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsDeleteReservationByHotelDate)                     .addStatement(bsDeleteReservationByConfirmation)                     .build();             cqlSession.execute(batchDeleteReservation);              \/\/ TODO: Publish message to Kafka with empty payload to indicate deletion             \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)             \/\/ with the reservation confirmation number as the key, and an empty string as the value             ProducerRecord&lt;String, String> record = null;             kafkaProducer.send(record);              return true;         }         return false;     }          \/**      * Search all reservation for an hotel id and LocalDate.      *      * @param hotelId      *      hotel identifier      * @param date      *      searched Date      * @return      *      list of reservations matching the search criteria      *\/     public List&lt;Reservation> findByHotelAndDate(String hotelId, LocalDate date) {         Objects.requireNonNull(hotelId);         Objects.requireNonNull(date);         return cqlSession.execute(psSearchReservation.bind(hotelId, date))                          .all()                          \/\/ no paging we retrieve all objects                          .stream()                       \/\/ because we are good people                          .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                          .collect(Collectors.toList());  \/\/ Back to list objects     }      \/**      * Utility method to marshal a row as expected Reservation Bean.      *      * @param row      *      current row from ResultSet      * @return      *      object      *\/     private Reservation mapRowToReservation(Row row) {         Reservation reservation = new Reservation();         reservation.setHotelId(row.getString(HOTEL_ID));         reservation.setConfirmationNumber(row.getString(CONFIRM_NUMBER));         reservation.setGuestId(row.getUuid(GUEST_ID));         reservation.setRoomNumber(row.getShort(ROOM_NUMBER));         reservation.setStartDate(row.getLocalDate(START_DATE));         reservation.setEndDate(row.getLocalDate(END_DATE));         return reservation;     }          \/**      * Create Keyspace and relevant tables as per defined in 'reservation.cql'      *\/     public void createReservationTables() {                  \/**          * Create TYPE 'Address' if not exists          *           * CREATE TYPE reservation.address (          *   street text,          *   city text,          *   state_or_province text,          *   postal_code text,          *   country text          * );          *\/         cqlSession.execute(                 createType(keyspaceName, TYPE_ADDRESS)                 .ifNotExists()                 .withField(STREET, DataTypes.TEXT)                 .withField(CITY, DataTypes.TEXT)                 .withField(STATE_PROVINCE, DataTypes.TEXT)                 .withField(POSTAL_CODE, DataTypes.TEXT)                 .withField(COUNTRY, DataTypes.TEXT)                 .build());         logger.debug(\"+ Type '{}' has been created (if needed)\", TYPE_ADDRESS.asInternal());                  \/**           * CREATE TABLE reservation.reservations_by_hotel_date (          *  hotel_id text,          *  start_date date,          *  end_date date,          *  room_number smallint,          *  confirm_number text,          *  guest_id uuid,          *  PRIMARY KEY ((hotel_id, start_date), room_number)          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                         .ifNotExists()                         .withPartitionKey(HOTEL_ID, DataTypes.TEXT)                         .withPartitionKey(START_DATE, DataTypes.DATE)                         .withClusteringColumn(ROOM_NUMBER, DataTypes.SMALLINT)                         .withColumn(END_DATE, DataTypes.DATE)                         .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                         .withColumn(GUEST_ID, DataTypes.UUID)                         .withClusteringOrder(ROOM_NUMBER, ClusteringOrder.ASC)                         .withComment(\"Q7. Find reservations by hotel and date\")                         .build());         logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_HOTEL_DATE.asInternal());                  \/**          * CREATE TABLE reservation.reservations_by_confirmation (          *   confirm_number text PRIMARY KEY,          *   hotel_id text,          *   start_date date,          *   end_date date,          *   room_number smallint,          *   guest_id uuid          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_CONFI)                 .ifNotExists()                 .withPartitionKey(CONFIRM_NUMBER, DataTypes.TEXT)                 .withColumn(HOTEL_ID, DataTypes.TEXT)                 .withColumn(START_DATE, DataTypes.DATE)                 .withColumn(END_DATE, DataTypes.DATE)                 .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                 .withColumn(GUEST_ID, DataTypes.UUID)                 .build());          logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_CONFI.asInternal());                    \/**           * CREATE TABLE reservation.reservations_by_guest (           *  guest_last_name text,           *  hotel_id text,           *  start_date date,           *  end_date date,           *  room_number smallint,           *  confirm_number text,           *  guest_id uuid,           *  PRIMARY KEY ((guest_last_name), hotel_id)           * );           *\/          cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_GUEST)                  .ifNotExists()                  .withPartitionKey(GUEST_LAST_NAME, DataTypes.TEXT)                  .withClusteringColumn(HOTEL_ID, DataTypes.TEXT)                  .withColumn(START_DATE, DataTypes.DATE)                  .withColumn(END_DATE, DataTypes.DATE)                  .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                  .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                  .withColumn(GUEST_ID, DataTypes.UUID)                  .withComment(\"Q8. Find reservations by guest name\")                  .build());           logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_GUEST.asInternal());                      \/**            * CREATE TABLE reservation.guests (            *   guest_id uuid PRIMARY KEY,            *   first_name text,            *   last_name text,            *   title text,            *   emails set&lt;text>,            *   phone_numbers list&lt;text>,            *   addresses map&lt;text, frozen&lt;address>>,            *   confirm_number text            * );            *\/           UserDefinedType  udtAddressType =                    cqlSession.getMetadata().getKeyspace(keyspaceName).get() \/\/ Retrieving KeySpaceMetadata                             .getUserDefinedType(TYPE_ADDRESS).get();        \/\/ Looking for UDT (extending DataType)           cqlSession.execute(createTable(keyspaceName, TABLE_GUESTS)                   .ifNotExists()                   .withPartitionKey(GUEST_ID, DataTypes.UUID)                   .withColumn(FIRSTNAME, DataTypes.TEXT)                   .withColumn(LASTNAME, DataTypes.TEXT)                   .withColumn(TITLE, DataTypes.TEXT)                   .withColumn(EMAILS, DataTypes.setOf(DataTypes.TEXT))                   .withColumn(PHONE_NUMBERS, DataTypes.listOf(DataTypes.TEXT))                   .withColumn(ADDRESSES, DataTypes.mapOf(DataTypes.TEXT, udtAddressType, true))                   .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                   .withComment(\"Q9. Find guest by ID\")                   .build());            logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_GUESTS.asInternal());            logger.info(\"Schema has been successfully initialized.\");     }      private void prepareStatements() {         if (psExistReservation == null) {             psExistReservation = cqlSession.prepare(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).column(CONFIRM_NUMBER)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psFindReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all()                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psSearchReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE).all()                                 .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                                 .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                                 .build());             psDeleteReservationByConfirmation = cqlSession.prepare(                                 deleteFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psDeleteReservationByHotelDate = cqlSession.prepare(                     deleteFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                     .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                     .where(column(ROOM_NUMBER).isEqualTo(bindMarker(ROOM_NUMBER)))                     .build());             psInsertReservationByHotelDate = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             psInsertReservationByConfirmation = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_CONFI)                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             logger.info(\"Statements have been successfully prepared.\");         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a Kafka <code>reservation-service\/src\/main\/java\/dev\/cassandraguide\/conf\/KafkaConfiguration.java<\/code>:<\/p>\n<pre><code>package dev.cassandraguide.conf;  import dev.cassandraguide.repository.ReservationRepository; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;  import org.apache.kafka.clients.producer.*; import org.apache.kafka.common.serialization.StringSerializer; import java.util.Properties;  \/**  * Import Configuration from Configuration File  *  * @author Jeff Carpenter  *\/ @Configuration public class KafkaConfiguration {      \/\/ Logger     private static final Logger logger = LoggerFactory.getLogger(ReservationRepository.class);      \/\/ Bootstrap servers     @Value(\"${kafka.bootstrap-servers:localhost:9092}\")     protected String bootstrapServers;      \/\/ Kafka Client ID     @Value(\"${kafka.client-id:ReservationService}\")     protected String clientId = \"ReservationService\";      \/\/ Topic Name     @Value(\"${kafka.topicName:reservation}\")     public String topicName = \"reservation\";      \/**      * Default configuration.      *\/     public KafkaConfiguration() {}      \/**      * Initialization of Configuration.      *      * @param bootstrapServers      * @param clientId      * @param topicName      *\/     public KafkaConfiguration(             String bootstrapServers, String clientId, String topicName) {         super();         this.bootstrapServers = bootstrapServers;         this.clientId = clientId;         this.topicName = topicName;     }      @Bean     public KafkaProducer&lt;String, String> kafkaProducer() {         logger.info(\"Creating Kafka Producer.\");          Properties props = new Properties();         props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);         props.put(ProducerConfig.CLIENT_ID_CONFIG, clientId);         props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());         props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());         return new KafkaProducer&lt;>(props);     }      \/**      * Getter accessor for attribute 'bootstrapServers'.      *      * @return      *       current value of 'bootstrapServers'      *\/     public String getBootstrapServers() {         return bootstrapServers;     }      \/**      * Setter accessor for attribute 'bootstrapServers'.      * @param bootstrapServers      * new value for 'bootstrapServers'      *\/     public void setBootstrapServers(String bootstrapServers) {         this.bootstrapServers = bootstrapServers;     }      \/**      * Getter accessor for attribute 'clientId'.      *      * @return      *       current value of 'clientId'      *\/     public String getClientId() {         return clientId;     }      \/**      * Setter accessor for attribute 'clientId'.      * @param clientId      * new value for 'clientId '      *\/     public void setClientId(String clientId) {         this.clientId = clientId;     }      \/**      * Getter accessor for attribute 'topicName'.      *      * @return      *       current value of 'topicName'      *\/     public String getTopicName() {         return topicName;     }      \/**      * Setter accessor for attribute 'topicName'.      * @param topicName      * new value for 'topicName '      *\/     public void setTopicName(String topicName) {         this.topicName = topicName;     }  }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u043b\u0443\u0436\u0431\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Cassandra \u0438 Kafka, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0434\u0435\u0441\u044c <code>reservation-service\/src\/main\/resources\/application.yml<\/code>:<\/p>\n<pre><code class=\"yaml\"># ---------------------------------------------------------- # Spring Boot Config # ---------------------------------------------------------- spring:   application:     name: Reservation Reservicess   jackson:     serialization:       WRITE_DATES_AS_TIMESTAMPS: false server:   port: 8080  # ---------------------------------------------------------- # DataStax Enterprise Java Driver Config # ---------------------------------------------------------- cassandra:   contactPoint: 127.0.0.1   port: 9042   keyspaceName: reservation   localDataCenterName: datacenter1   dropSchema: false  # ---------------------------------------------------------- # Kafka Producer Config # ---------------------------------------------------------- kafka:   bootstrap-servers: localhost:9092   client-id: ReservationService   topicName: reservation <\/code><\/pre>\n<h2>\u0422\u0430\u0431\u043b\u0438\u0446\u044b Cassandra \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0439<\/h2>\n<p>\u0412 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432 Cassandra \u0432\u0445\u043e\u0434\u0438\u0442 <code>cqlsh<\/code>, \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430 \u0434\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u043d\u0430 CQL. \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0443:<\/p>\n<p><code>apache-cassandra-4.0-alpha4\/bin\/cqlsh<br \/><\/code><br \/>\u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435 <code>cqlsh><\/code> \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8af\/ffb\/ea0\/8afffbea0d7a71b56547a3c58ecd0b09.png\" alt=\"\" title=\"\" width=\"1001\" height=\"134\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8af\/ffb\/ea0\/8afffbea0d7a71b56547a3c58ecd0b09.png\"\/><\/figure>\n<p>\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441\u0445\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043a\u043b\u044e\u0447\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p><code>SOURCE 'reservation-service\/src\/main\/resources\/reservation.cql';<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>DESCRIBE<\/code>:<\/p>\n<p><code>DESCRIBE KEYSPACE reservation;<\/code><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u044d\u0442\u043e \u043a\u0430\u043a \u043a\u0435\u0439\u0441\u043f\u0435\u0439\u0441 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<p><code>USE reservation;<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d54\/98c\/e6f\/d5498ce6f4a58d0430b32baef43c2f1d.png\" alt=\"\" title=\"\" width=\"1261\" height=\"247\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d54\/98c\/e6f\/d5498ce6f4a58d0430b32baef43c2f1d.png\"\/><\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ea1\/311\/6c9\/ea13116c9a77a8debe104917b9ed51ec.png\" alt=\"\" title=\"\" width=\"1257\" height=\"347\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ea1\/311\/6c9\/ea13116c9a77a8debe104917b9ed51ec.png\"\/><\/figure>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438, \u043d\u043e \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043b\u044e\u0447\u0430\u043c\u0438.<\/p>\n<p>\u041d\u0430\u0448\u0430 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044f \u043a\u0430\u043a \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0441\u0442\u043e\u0432 \u043f\u043e \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0431\u044b \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043f\u0440\u043e\u0444\u0438\u043b\u0438 \u0433\u043e\u0441\u0442\u0435\u0439, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f. \u041d\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 Cassandra \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u043d\u0430\u0448\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. \u042d\u0442\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442, \u043a\u0430\u043a \u0432\u0430\u0448\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0434\u0435\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u0434\u0438\u0437\u0430\u0439\u043d\u0443.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>reservations_by_confirmation<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0438\u0441\u043a \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"xml\">CREATE TABLE reservations_by_confirmation  (  confirm_number text,  hotel_id text,  start_date date,  end_date date,  room_number smallint,  guest_id uuid,  PRIMARY KEY (confirm_number) )<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<p><code>INSERT INTO reservations_by_confirmation (confirm_number, hotel_id, start_date, end_date, room_number, guest_id) VALUES ('RS2G0Z', 'NY456', '2020-06-08', '2020-06-10', 111, 1b4d86f4-ccff-4256-a63d-45c905df2677);<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e63\/ffa\/793\/e63ffa793686a5a6df94bf21aa71f750.png\" alt=\"\" title=\"\" width=\"1234\" height=\"178\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e63\/ffa\/793\/e63ffa793686a5a6df94bf21aa71f750.png\"\/><\/figure>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u043f\u043e\u0437\u0436\u0435, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<p><code>SELECT * FROM reservations_by_confirmation WHERE confirm_number = 'RS2G0Z';<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cf1\/c35\/9e9\/cf1c359e9ee16c603a635f20b59a88e0.png\" alt=\"\" title=\"\" width=\"1256\" height=\"293\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cf1\/c35\/9e9\/cf1c359e9ee16c603a635f20b59a88e0.png\"\/><\/figure>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>reservations_by_hotel_date<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0443 \u043e\u0442\u0435\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0439 \u043f\u043e \u0434\u0430\u0442\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u0435\u043b\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u0435\u043b\u044c \u0431\u044b\u043b \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d \u0438\u043b\u0438 \u043d\u0435 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d:<\/p>\n<p><code>CREATE TABLE reservations_by_hotel_date ( hotel_id text, start_date date, end_date date, room_number smallint, confirm_number text, guest_id uuid, PRIMARY KEY ((hotel_id, start_date), room_number) );<\/code><\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0442\u043e\u0439 \u0436\u0435 \u0431\u0440\u043e\u043d\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u0432 <code>reservations_by_confirmation<\/code>, \u0432 \u044d\u0442\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443:<\/p>\n<p><code>INSERT INTO reservations_by_hotel_date (confirm_number, hotel_id, start_date, end_date, room_number, guest_id) VALUES ('RS2G0Z', 'NY456', '2020-06-08', '2020-06-10', 111, 1b4d86f4-ccff-4256-a63d-45c905df2677);<\/code><\/p>\n<p>\u042d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a\u043b\u044e\u0447 \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 hotel_id \u0438 start_date, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u0442\u0435\u043b\u044f \u0438 \u0434\u0430\u0442\u044b:<\/p>\n<p><code>SELECT * FROM reservations_by_hotel_date WHERE hotel_id = 'NY456' AND start_date = '2020-06-08';<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b08\/138\/cee\/b08138cee2294a6814501671e51bf72a.png\" alt=\"\" title=\"\" width=\"1251\" height=\"300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b08\/138\/cee\/b08138cee2294a6814501671e51bf72a.png\"\/><\/figure>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0431\u0440\u043e\u043d\u044c \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e \u0434\u0430\u0442\u0435:<\/p>\n<p><code>SELECT * FROM reservations_by_hotel_date WHERE hotel_id = 'NY456' AND start_date = '2020-06-08' AND room_number = 111;<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/505\/20c\/921\/50520c921923458f37d85220fc490e8b.png\" alt=\"\" title=\"\" width=\"1248\" height=\"300\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/505\/20c\/921\/50520c921923458f37d85220fc490e8b.png\"\/><\/figure>\n<p>\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>reservations_by_guest<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u0438\u043c\u0435\u043d\u0438 \u0433\u043e\u0441\u0442\u044f \u0434\u043b\u044f \u0433\u043e\u0441\u0442\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0431\u044b\u043b \u0441\u0432\u043e\u0439 \u043d\u043e\u043c\u0435\u0440 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 <code>reservations_by_confirmation<\/code> \u0438 <code>reservations_by_hotel_date<\/code>.<\/p>\n<p>\u041c\u044b \u0437\u0430\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 <code>ReservationRepository<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 Cassandra BATCH \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 <code>reservations_by_confirmation<\/code> \u0438 <code>reservations_by_hotel_date<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043a\u0430\u043a \u043e\u0434\u043d\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f CQL <code>reservation-service\/src\/main\/java\/dev\/cassandraguide\/repository\/ReservationRepository.java<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>ReservationRepository.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"java\">\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * 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.  *\/ package dev.cassandraguide.repository;  import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createType; import static com.datastax.oss.driver.api.querybuilder.relation.Relation.column;  import java.time.LocalDate; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors;  import javax.annotation.PreDestroy;  import com.fasterxml.jackson.core.JsonProcessingException; import dev.cassandraguide.model.Reservation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Profile; import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository;  import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.cql.BatchStatement; import com.datastax.oss.driver.api.core.cql.BoundStatement; import com.datastax.oss.driver.api.core.cql.DefaultBatchType; import com.datastax.oss.driver.api.core.cql.PreparedStatement; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.core.type.DataTypes; import com.datastax.oss.driver.api.core.type.UserDefinedType; import com.datastax.oss.driver.api.querybuilder.QueryBuilder;  \/\/ TODO: Review imports for publishing to Kafka import org.apache.kafka.clients.producer.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;  \/**  * The goal of this project is to provide a minimally functional implementation of a microservice   * that uses Apache Cassandra for its data storage. The reservation service is implemented as a   * RESTful service using Spring Boot.  *  * @author Jeff Carpenter, Cedrick Lunven  *\/ @Repository @Profile(\"!unit-test\") \/\/ When I do some 'unit-test' no connectivity to DB public class ReservationRepository {      \/** Logger for the class. *\/     private static final Logger logger = LoggerFactory.getLogger(ReservationRepository.class);          \/\/ Reservation Schema Constants     public static final CqlIdentifier TYPE_ADDRESS               = CqlIdentifier.fromCql(\"address\");     public static final CqlIdentifier TABLE_RESERVATION_BY_HOTEL_DATE =             CqlIdentifier.fromCql(\"reservations_by_hotel_date\");     public static final CqlIdentifier TABLE_RESERVATION_BY_CONFI = CqlIdentifier.fromCql(\"reservations_by_confirmation\");     public static final CqlIdentifier TABLE_RESERVATION_BY_GUEST = CqlIdentifier.fromCql(\"reservations_by_guest\");     public static final CqlIdentifier TABLE_GUESTS               = CqlIdentifier.fromCql(\"guests\");     public static final CqlIdentifier STREET                     = CqlIdentifier.fromCql(\"street\");     public static final CqlIdentifier CITY                       = CqlIdentifier.fromCql(\"city\");     public static final CqlIdentifier STATE_PROVINCE             = CqlIdentifier.fromCql(\"state_or_province\");     public static final CqlIdentifier POSTAL_CODE                = CqlIdentifier.fromCql(\"postal_code\");     public static final CqlIdentifier COUNTRY                    = CqlIdentifier.fromCql(\"country\");     public static final CqlIdentifier HOTEL_ID                   = CqlIdentifier.fromCql(\"hotel_id\");     public static final CqlIdentifier START_DATE                 = CqlIdentifier.fromCql(\"start_date\");     public static final CqlIdentifier END_DATE                   = CqlIdentifier.fromCql(\"end_date\");     public static final CqlIdentifier ROOM_NUMBER                = CqlIdentifier.fromCql(\"room_number\");     public static final CqlIdentifier CONFIRM_NUMBER             = CqlIdentifier.fromCql(\"confirm_number\");     public static final CqlIdentifier GUEST_ID                   = CqlIdentifier.fromCql(\"guest_id\");     public static final CqlIdentifier GUEST_LAST_NAME            = CqlIdentifier.fromCql(\"guest_last_name\");     public static final CqlIdentifier FIRSTNAME                  = CqlIdentifier.fromCql(\"first_name\");     public static final CqlIdentifier LASTNAME                   = CqlIdentifier.fromCql(\"last_name\");     public static final CqlIdentifier TITLE                      = CqlIdentifier.fromCql(\"title\");     public static final CqlIdentifier EMAILS                     = CqlIdentifier.fromCql(\"emails\");     public static final CqlIdentifier PHONE_NUMBERS              = CqlIdentifier.fromCql(\"phone_numbers\");     public static final CqlIdentifier ADDRESSES                  = CqlIdentifier.fromCql(\"addresses\");          private PreparedStatement psExistReservation;     private PreparedStatement psFindReservation;     private PreparedStatement psInsertReservationByHotelDate;     private PreparedStatement psInsertReservationByConfirmation;     private PreparedStatement psDeleteReservationByHotelDate;     private PreparedStatement psDeleteReservationByConfirmation;     private PreparedStatement psSearchReservation;          \/** CqlSession holding metadata to interact with Cassandra. *\/     private CqlSession     cqlSession;     private CqlIdentifier  keyspaceName;      \/\/ TODO: Review variables used for publishing to Kafka     \/** KafkaProducer for publishing messages to Kafka. *\/     private KafkaProducer&lt;String, String> kafkaProducer;     private String kafkaTopicName;     private ObjectMapper objectMapper;          \/** External Initialization. *\/     public ReservationRepository(             @NonNull CqlSession cqlSession,              @Qualifier(\"keyspace\") @NonNull CqlIdentifier keyspaceName,             @NonNull KafkaProducer&lt;String, String> kafkaProducer,             @NonNull String kafkaTopicName) {         this.cqlSession   = cqlSession;         this.keyspaceName = keyspaceName;          \/\/ TODO: Review initialization of objects needed for publishing to Kafka         this.kafkaProducer = kafkaProducer;         this.kafkaTopicName = kafkaTopicName;          objectMapper = new ObjectMapper();         objectMapper.registerModule(new JavaTimeModule());         objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);         objectMapper.enable(SerializationFeature.INDENT_OUTPUT);          \/\/ Will create tables (if they do not exist)         createReservationTables();                  \/\/ Prepare Statements of reservation         prepareStatements();         logger.info(\"Application initialized.\");     }          \/**      * CqlSession is a stateful object handling TCP connections to nodes in the cluster.      * This operation properly closes sockets when the application is stopped      *\/     @PreDestroy     public void cleanup() {         if (null != cqlSession) {             cqlSession.close();             logger.info(\"+ CqlSession has been successfully closed\");         }     }          \/**      * Testing existence is useful for building correct semantics in the RESTful API. To evaluate existence find the      * table where confirmation number is partition key which is reservations_by_confirmation      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      true if the reservation exists, false if it does not      *\/     public boolean exists(String confirmationNumber) {         return cqlSession.execute(psExistReservation.bind(confirmationNumber))                          .getAvailableWithoutFetching() > 0;     }          \/**      * Similar to exists() but maps and parses results.      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      reservation if present or empty      *\/     @NonNull     public Optional&lt;Reservation> findByConfirmationNumber(@NonNull String confirmationNumber) {                  ResultSet resultSet = cqlSession.execute(psFindReservation.bind(confirmationNumber));                  \/\/ Hint: an empty result might not be an error as this method is sometimes used to check whether a         \/\/ reservation with this confirmation number exists         Row row = resultSet.one();         if (row == null) {             logger.debug(\"Unable to load reservation with confirmation number: \" + confirmationNumber);             return Optional.empty();         }                  \/\/ Hint: If there is a result, create a new reservation object and set the values         \/\/ Bonus: factor the logic to extract a reservation from a row into a separate method         \/\/ (you will reuse it again later in getAllReservations())         return Optional.of(mapRowToReservation(row));     }          \/**      * Create new entry in multiple tables for this reservation.      *      * @param reservation      *      current reservation object      * @return      *      confirmation number for the reservation      *            *\/      public String upsert(Reservation reservation) {         Objects.requireNonNull(reservation);         if (null == reservation.getConfirmationNumber()) {             \/\/ Generating a new reservation number if none has been provided             reservation.setConfirmationNumber(UUID.randomUUID().toString());         }         \/\/ Insert into 'reservations_by_hotel_date'         BoundStatement bsInsertReservationByHotel =                  psInsertReservationByHotelDate.bind(reservation.getHotelId(), reservation.getStartDate(),                         reservation.getEndDate(), reservation.getRoomNumber(), reservation.getConfirmationNumber(),                         reservation.getGuestId());         \/\/ Insert into 'reservations_by_confirmation'         BoundStatement bsInsertReservationByConfirmation =                  psInsertReservationByConfirmation.bind(reservation.getConfirmationNumber(), reservation.getHotelId(),                         reservation.getStartDate(), reservation.getEndDate(), reservation.getRoomNumber(),                         reservation.getGuestId());         BatchStatement batchInsertReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsInsertReservationByHotel)                     .addStatement(bsInsertReservationByConfirmation)                     .build();         cqlSession.execute(batchInsertReservation);          \/\/ TODO: Publish message to Kafka containing reservation          try {              String reservationJson = objectMapper.writeValueAsString(reservation);              \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)              \/\/ with the reservation confirmation number as the key, and the JSON string as the value              ProducerRecord&lt;String, String> record = null;              kafkaProducer.send(record);          } catch (Exception e) {              logger.warn(\"Error publishing reservation message to Kafka: {}\", e);          }          return reservation.getConfirmationNumber();     }      \/**      * We pick 'reservations_by_confirmation' table to list reservations      * BUT we could have used 'reservations_by_hotel_date' (as no key provided in request)      *        * @return      *      list containing all reservations      *\/     public List&lt;Reservation> findAll() {         return cqlSession.execute(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all().build())                   .all()                          \/\/ no paging we retrieve all objects                   .stream()                       \/\/ because we are good people                   .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                   .collect(Collectors.toList());  \/\/ Back to list objects     }            \/**      * Deleting a reservation.      *      * @param confirmationNumber      *      unique identifier for confirmation.      *\/     public boolean delete(String confirmationNumber) {          \/\/ Retrieving entire reservation in order to obtain the attributes we will need to delete from         \/\/ reservations_by_hotel_date table         Optional&lt;Reservation> reservationToDelete = this.findByConfirmationNumber(confirmationNumber);          if (reservationToDelete.isPresent()) {              \/\/ Delete from 'reservations_by_hotel_date'             Reservation reservation = reservationToDelete.get();             BoundStatement bsDeleteReservationByHotelDate =                     psDeleteReservationByHotelDate.bind(reservation.getHotelId(),                             reservation.getStartDate(), reservation.getRoomNumber());              \/\/ Delete from 'reservations_by_confirmation'             BoundStatement bsDeleteReservationByConfirmation =                     psDeleteReservationByConfirmation.bind(confirmationNumber);              BatchStatement batchDeleteReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsDeleteReservationByHotelDate)                     .addStatement(bsDeleteReservationByConfirmation)                     .build();             cqlSession.execute(batchDeleteReservation);              \/\/ TODO: Publish message to Kafka with empty payload to indicate deletion             \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)             \/\/ with the reservation confirmation number as the key, and an empty string as the value             ProducerRecord&lt;String, String> record = null;             kafkaProducer.send(record);              return true;         }         return false;     }          \/**      * Search all reservation for an hotel id and LocalDate.      *      * @param hotelId      *      hotel identifier      * @param date      *      searched Date      * @return      *      list of reservations matching the search criteria      *\/     public List&lt;Reservation> findByHotelAndDate(String hotelId, LocalDate date) {         Objects.requireNonNull(hotelId);         Objects.requireNonNull(date);         return cqlSession.execute(psSearchReservation.bind(hotelId, date))                          .all()                          \/\/ no paging we retrieve all objects                          .stream()                       \/\/ because we are good people                          .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                          .collect(Collectors.toList());  \/\/ Back to list objects     }      \/**      * Utility method to marshal a row as expected Reservation Bean.      *      * @param row      *      current row from ResultSet      * @return      *      object      *\/     private Reservation mapRowToReservation(Row row) {         Reservation reservation = new Reservation();         reservation.setHotelId(row.getString(HOTEL_ID));         reservation.setConfirmationNumber(row.getString(CONFIRM_NUMBER));         reservation.setGuestId(row.getUuid(GUEST_ID));         reservation.setRoomNumber(row.getShort(ROOM_NUMBER));         reservation.setStartDate(row.getLocalDate(START_DATE));         reservation.setEndDate(row.getLocalDate(END_DATE));         return reservation;     }          \/**      * Create Keyspace and relevant tables as per defined in 'reservation.cql'      *\/     public void createReservationTables() {                  \/**          * Create TYPE 'Address' if not exists          *           * CREATE TYPE reservation.address (          *   street text,          *   city text,          *   state_or_province text,          *   postal_code text,          *   country text          * );          *\/         cqlSession.execute(                 createType(keyspaceName, TYPE_ADDRESS)                 .ifNotExists()                 .withField(STREET, DataTypes.TEXT)                 .withField(CITY, DataTypes.TEXT)                 .withField(STATE_PROVINCE, DataTypes.TEXT)                 .withField(POSTAL_CODE, DataTypes.TEXT)                 .withField(COUNTRY, DataTypes.TEXT)                 .build());         logger.debug(\"+ Type '{}' has been created (if needed)\", TYPE_ADDRESS.asInternal());                  \/**           * CREATE TABLE reservation.reservations_by_hotel_date (          *  hotel_id text,          *  start_date date,          *  end_date date,          *  room_number smallint,          *  confirm_number text,          *  guest_id uuid,          *  PRIMARY KEY ((hotel_id, start_date), room_number)          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                         .ifNotExists()                         .withPartitionKey(HOTEL_ID, DataTypes.TEXT)                         .withPartitionKey(START_DATE, DataTypes.DATE)                         .withClusteringColumn(ROOM_NUMBER, DataTypes.SMALLINT)                         .withColumn(END_DATE, DataTypes.DATE)                         .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                         .withColumn(GUEST_ID, DataTypes.UUID)                         .withClusteringOrder(ROOM_NUMBER, ClusteringOrder.ASC)                         .withComment(\"Q7. Find reservations by hotel and date\")                         .build());         logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_HOTEL_DATE.asInternal());                  \/**          * CREATE TABLE reservation.reservations_by_confirmation (          *   confirm_number text PRIMARY KEY,          *   hotel_id text,          *   start_date date,          *   end_date date,          *   room_number smallint,          *   guest_id uuid          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_CONFI)                 .ifNotExists()                 .withPartitionKey(CONFIRM_NUMBER, DataTypes.TEXT)                 .withColumn(HOTEL_ID, DataTypes.TEXT)                 .withColumn(START_DATE, DataTypes.DATE)                 .withColumn(END_DATE, DataTypes.DATE)                 .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                 .withColumn(GUEST_ID, DataTypes.UUID)                 .build());          logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_CONFI.asInternal());                    \/**           * CREATE TABLE reservation.reservations_by_guest (           *  guest_last_name text,           *  hotel_id text,           *  start_date date,           *  end_date date,           *  room_number smallint,           *  confirm_number text,           *  guest_id uuid,           *  PRIMARY KEY ((guest_last_name), hotel_id)           * );           *\/          cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_GUEST)                  .ifNotExists()                  .withPartitionKey(GUEST_LAST_NAME, DataTypes.TEXT)                  .withClusteringColumn(HOTEL_ID, DataTypes.TEXT)                  .withColumn(START_DATE, DataTypes.DATE)                  .withColumn(END_DATE, DataTypes.DATE)                  .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                  .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                  .withColumn(GUEST_ID, DataTypes.UUID)                  .withComment(\"Q8. Find reservations by guest name\")                  .build());           logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_GUEST.asInternal());                      \/**            * CREATE TABLE reservation.guests (            *   guest_id uuid PRIMARY KEY,            *   first_name text,            *   last_name text,            *   title text,            *   emails set&lt;text>,            *   phone_numbers list&lt;text>,            *   addresses map&lt;text, frozen&lt;address>>,            *   confirm_number text            * );            *\/           UserDefinedType  udtAddressType =                    cqlSession.getMetadata().getKeyspace(keyspaceName).get() \/\/ Retrieving KeySpaceMetadata                             .getUserDefinedType(TYPE_ADDRESS).get();        \/\/ Looking for UDT (extending DataType)           cqlSession.execute(createTable(keyspaceName, TABLE_GUESTS)                   .ifNotExists()                   .withPartitionKey(GUEST_ID, DataTypes.UUID)                   .withColumn(FIRSTNAME, DataTypes.TEXT)                   .withColumn(LASTNAME, DataTypes.TEXT)                   .withColumn(TITLE, DataTypes.TEXT)                   .withColumn(EMAILS, DataTypes.setOf(DataTypes.TEXT))                   .withColumn(PHONE_NUMBERS, DataTypes.listOf(DataTypes.TEXT))                   .withColumn(ADDRESSES, DataTypes.mapOf(DataTypes.TEXT, udtAddressType, true))                   .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                   .withComment(\"Q9. Find guest by ID\")                   .build());            logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_GUESTS.asInternal());            logger.info(\"Schema has been successfully initialized.\");     }      private void prepareStatements() {         if (psExistReservation == null) {             psExistReservation = cqlSession.prepare(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).column(CONFIRM_NUMBER)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psFindReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all()                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psSearchReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE).all()                                 .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                                 .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                                 .build());             psDeleteReservationByConfirmation = cqlSession.prepare(                                 deleteFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psDeleteReservationByHotelDate = cqlSession.prepare(                     deleteFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                     .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                     .where(column(ROOM_NUMBER).isEqualTo(bindMarker(ROOM_NUMBER)))                     .build());             psInsertReservationByHotelDate = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             psInsertReservationByConfirmation = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_CONFI)                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             logger.info(\"Statements have been successfully prepared.\");         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>cqlsh<\/code>, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u044b\u0439\u0434\u0435\u043c:<\/p>\n<p><code>Exit<\/code><\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Apache Kafka<\/h4>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0438 \u0441\u043b\u0443\u0436\u0431\u044b \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 Apache Kafka.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Kafka:<\/p>\n<p><code>wget<\/code> <a href=\"http:\/\/archive.apache.org\/dist\/kafka\/2.5.0\/kafka_2.12-2.5.0.tgz\"><u>http:\/\/archive.apache.org\/dist\/kafka\/2.5.0\/kafka_2.12-2.5.0.tgz<\/u><\/p>\n<p><\/a><code>tar xzf kafka_2.12-2.5.0.tgz<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u0430\u043f\u043a\u0430 \u0432 \u0432\u0430\u0448\u0435\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>_kafka_x.x-x.x.x_<\/code> (\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0432\u0435\u0440\u0441\u0438\u0439 Scala \u0438 Kafka \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e).<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440 Kafka \u0441 \u043e\u0434\u043d\u0438\u043c \u0443\u0437\u043b\u043e\u043c, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: Zookeeper \u0438 \u0431\u0440\u043e\u043a\u0435\u0440 Kafka. Kafka \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 Zookeeper \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043a\u0430\u0436\u0434\u044b\u043c \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u043c \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0431\u0440\u043e\u043a\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c. Zookeeper \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0443\u0449\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u0431\u0440\u043e\u043a\u0435\u0440 \u043c\u043e\u0433 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c Zookeeper \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<p><code>kafka_2.12-2.5.0\/bin\/zookeeper-server-start.sh kafka_2.12-2.5.0\/config\/zookeeper.properties &amp;> zookeeper_start.log &amp;<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0431\u0440\u043e\u043a\u0435\u0440\u0430 Kafka:<\/p>\n<p><code>kafka_2.12-2.5.0\/bin\/kafka-server-start.sh kafka_2.12-2.5.0\/config\/server.properties &amp;> kafka_start.log &amp;<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e90\/462\/7f5\/e904627f502a29fd0b604582c28f4599.png\" alt=\"\" title=\"\" width=\"1248\" height=\"171\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e90\/462\/7f5\/e904627f502a29fd0b604582c28f4599.png\"\/><\/figure>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0435\u043c Kafka Topic \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f<\/h2>\n<p>Kafka \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0438\u043b\u044c \u043e\u0431\u043c\u0435\u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0442\u0441\u044f \u0432 \u0442\u0435\u043c\u0430\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0434\u043e\u0431\u043d\u043e Cassandra, Kafka \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0430 \u0438 \u0440\u0435\u043f\u043b\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0443\u0437\u043b\u0430\u043c\u0438, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u043c\u0438 \u043a\u0430\u043a \u0431\u0440\u043e\u043a\u0435\u0440\u044b \u0432 Kafka.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u043e\u043f\u0438\u043a Kafka \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p><code>kafka_2.12-2.5.0\/bin\/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic reservation --config retention.ms=-1<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d83\/c2a\/b3a\/d83c2ab3a67e961708449113f27d0b33.png\" alt=\"\" title=\"\" width=\"1252\" height=\"81\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d83\/c2a\/b3a\/d83c2ab3a67e961708449113f27d0b33.png\"\/><\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0441\u043b\u0443\u0436\u0431\u0443 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 Kafka \u043e \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b API \u043f\u043e\u043d\u0435\u043c\u043d\u043e\u0433\u0443, \u0438 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c\u0438 \u0432 jshell, Java REPL, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u0434 \u0432 \u0441\u043b\u0443\u0436\u0431\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p><code>cd reservation-service mvn -q compile com.github.johnpoth:jshell-maven-plugin:1.3:run<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/399\/fbf\/940\/399fbf940f9682153e34eb9a0e1e6466.png\" alt=\"\" title=\"\" width=\"1257\" height=\"247\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/399\/fbf\/940\/399fbf940f9682153e34eb9a0e1e6466.png\"\/><\/figure>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c KafkaProducer, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0442\u043e\u043f\u0438\u043a\u0435 Kafka:<\/p>\n<p><code>import org.apache.kafka.clients.producer.*; import org.apache.kafka.common.serialization.StringSerializer; import java.util.Properties; Properties props = new Properties(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, \"localhost:9092\"); props.put(ProducerConfig.CLIENT_ID_CONFIG, \"ReservationService\"); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); KafkaProducer&lt;String, String> producer = new KafkaProducer&lt;>(props);<\/code>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442 Reservation, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043b\u0443\u0436\u0431\u0430 Reservation \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430\u043c\u0438 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<p><code>import java.time.LocalDate; import java.util.UUID; import dev.cassandraguide.model.Reservation; String confirmationNumber = \"RS2G0Z\" Reservation reservation = new Reservation(); reservation.setConfirmationNumber(confirmationNumber); reservation.setStartDate(LocalDate.now()); reservation.setEndDate(LocalDate.now().plusDays(2)); reservation.setHotelId(\"NY456\"); reservation.setGuestId(UUID.fromString(\"1b4d86f4-ccff-4256-a63d-45c905df2677\")); reservation.setRoomNumber((short)111);<\/code><\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443 JSON, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Jackson ObjectMapper:<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u0432 objectMapper, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u044b \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439 \u043f\u0435\u0447\u0430\u0442\u0438 JSON. \u0427\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c:<\/p>\n<p><code>System.out.println(reservationJson)<\/code>;<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/73d\/a2e\/d19\/73da2ed19844f4bf8c2face0c7641c44.png\" alt=\"\" title=\"\" width=\"737\" height=\"261\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/73d\/a2e\/d19\/73da2ed19844f4bf8c2face0c7641c44.png\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u043f\u0438\u043a\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Kafka, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>confirmNumber<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0430 \u0438 <code>reservationJson<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438:<\/p>\n<p><code>ProducerRecord&lt;String, String> record = new ProducerRecord&lt;>(\"reservation\", confirmationNumber, reservationJson); producer.send(record);<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a1a\/4f1\/17e\/a1a4f117e2d614186ccdcc79267900a1.png\" alt=\"\" title=\"\" width=\"1258\" height=\"209\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a1a\/4f1\/17e\/a1a4f117e2d614186ccdcc79267900a1.png\"\/><\/figure>\n<p>\u0412\u044b\u0439\u0434\u0435\u043c \u0438\u0437 <code>jshell<\/code>: <code>exit<\/code><\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u043e\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0438:<\/p>\n<p><code>cd kafka_2.12-2.5.0\/bin\/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic reservation --max-messages 10<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d8\/d5c\/47c\/9d8d5c47c36ca955ed5b5e26a715ee26.png\" alt=\"\" title=\"\" width=\"1266\" height=\"274\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d8\/d5c\/47c\/9d8d5c47c36ca955ed5b5e26a715ee26.png\"\/><\/figure>\n<p>\u0412\u044b\u0439\u0442\u0438 \u0438\u0437 \u043a\u043e\u043d\u0441\u044c\u044e\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Ctrl+C.<\/p>\n<h2>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043b\u0443\u0436\u0431\u044b \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Kafka<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u044b\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Kafka, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u043c \u0441\u043b\u0443\u0436\u0431\u0443 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 Kafka \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u043a\u043b\u0430\u0441\u0441 <code>ReservationRepository<\/code>:<\/p>\n<details class=\"spoiler\">\n<summary>ReservationRepository.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * 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.  *\/ package dev.cassandraguide.repository;  import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createType; import static com.datastax.oss.driver.api.querybuilder.relation.Relation.column;  import java.time.LocalDate; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors;  import javax.annotation.PreDestroy;  import com.fasterxml.jackson.core.JsonProcessingException; import dev.cassandraguide.model.Reservation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Profile; import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository;  import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.cql.BatchStatement; import com.datastax.oss.driver.api.core.cql.BoundStatement; import com.datastax.oss.driver.api.core.cql.DefaultBatchType; import com.datastax.oss.driver.api.core.cql.PreparedStatement; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.core.type.DataTypes; import com.datastax.oss.driver.api.core.type.UserDefinedType; import com.datastax.oss.driver.api.querybuilder.QueryBuilder;  \/\/ TODO: Review imports for publishing to Kafka import org.apache.kafka.clients.producer.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;  \/**  * The goal of this project is to provide a minimally functional implementation of a microservice   * that uses Apache Cassandra for its data storage. The reservation service is implemented as a   * RESTful service using Spring Boot.  *  * @author Jeff Carpenter, Cedrick Lunven  *\/ @Repository @Profile(\"!unit-test\") \/\/ When I do some 'unit-test' no connectivity to DB public class ReservationRepository {      \/** Logger for the class. *\/     private static final Logger logger = LoggerFactory.getLogger(ReservationRepository.class);          \/\/ Reservation Schema Constants     public static final CqlIdentifier TYPE_ADDRESS               = CqlIdentifier.fromCql(\"address\");     public static final CqlIdentifier TABLE_RESERVATION_BY_HOTEL_DATE =             CqlIdentifier.fromCql(\"reservations_by_hotel_date\");     public static final CqlIdentifier TABLE_RESERVATION_BY_CONFI = CqlIdentifier.fromCql(\"reservations_by_confirmation\");     public static final CqlIdentifier TABLE_RESERVATION_BY_GUEST = CqlIdentifier.fromCql(\"reservations_by_guest\");     public static final CqlIdentifier TABLE_GUESTS               = CqlIdentifier.fromCql(\"guests\");     public static final CqlIdentifier STREET                     = CqlIdentifier.fromCql(\"street\");     public static final CqlIdentifier CITY                       = CqlIdentifier.fromCql(\"city\");     public static final CqlIdentifier STATE_PROVINCE             = CqlIdentifier.fromCql(\"state_or_province\");     public static final CqlIdentifier POSTAL_CODE                = CqlIdentifier.fromCql(\"postal_code\");     public static final CqlIdentifier COUNTRY                    = CqlIdentifier.fromCql(\"country\");     public static final CqlIdentifier HOTEL_ID                   = CqlIdentifier.fromCql(\"hotel_id\");     public static final CqlIdentifier START_DATE                 = CqlIdentifier.fromCql(\"start_date\");     public static final CqlIdentifier END_DATE                   = CqlIdentifier.fromCql(\"end_date\");     public static final CqlIdentifier ROOM_NUMBER                = CqlIdentifier.fromCql(\"room_number\");     public static final CqlIdentifier CONFIRM_NUMBER             = CqlIdentifier.fromCql(\"confirm_number\");     public static final CqlIdentifier GUEST_ID                   = CqlIdentifier.fromCql(\"guest_id\");     public static final CqlIdentifier GUEST_LAST_NAME            = CqlIdentifier.fromCql(\"guest_last_name\");     public static final CqlIdentifier FIRSTNAME                  = CqlIdentifier.fromCql(\"first_name\");     public static final CqlIdentifier LASTNAME                   = CqlIdentifier.fromCql(\"last_name\");     public static final CqlIdentifier TITLE                      = CqlIdentifier.fromCql(\"title\");     public static final CqlIdentifier EMAILS                     = CqlIdentifier.fromCql(\"emails\");     public static final CqlIdentifier PHONE_NUMBERS              = CqlIdentifier.fromCql(\"phone_numbers\");     public static final CqlIdentifier ADDRESSES                  = CqlIdentifier.fromCql(\"addresses\");          private PreparedStatement psExistReservation;     private PreparedStatement psFindReservation;     private PreparedStatement psInsertReservationByHotelDate;     private PreparedStatement psInsertReservationByConfirmation;     private PreparedStatement psDeleteReservationByHotelDate;     private PreparedStatement psDeleteReservationByConfirmation;     private PreparedStatement psSearchReservation;          \/** CqlSession holding metadata to interact with Cassandra. *\/     private CqlSession     cqlSession;     private CqlIdentifier  keyspaceName;      \/\/ TODO: Review variables used for publishing to Kafka     \/** KafkaProducer for publishing messages to Kafka. *\/     private KafkaProducer&lt;String, String> kafkaProducer;     private String kafkaTopicName;     private ObjectMapper objectMapper;          \/** External Initialization. *\/     public ReservationRepository(             @NonNull CqlSession cqlSession,              @Qualifier(\"keyspace\") @NonNull CqlIdentifier keyspaceName,             @NonNull KafkaProducer&lt;String, String> kafkaProducer,             @NonNull String kafkaTopicName) {         this.cqlSession   = cqlSession;         this.keyspaceName = keyspaceName;          \/\/ TODO: Review initialization of objects needed for publishing to Kafka         this.kafkaProducer = kafkaProducer;         this.kafkaTopicName = kafkaTopicName;          objectMapper = new ObjectMapper();         objectMapper.registerModule(new JavaTimeModule());         objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);         objectMapper.enable(SerializationFeature.INDENT_OUTPUT);          \/\/ Will create tables (if they do not exist)         createReservationTables();                  \/\/ Prepare Statements of reservation         prepareStatements();         logger.info(\"Application initialized.\");     }          \/**      * CqlSession is a stateful object handling TCP connections to nodes in the cluster.      * This operation properly closes sockets when the application is stopped      *\/     @PreDestroy     public void cleanup() {         if (null != cqlSession) {             cqlSession.close();             logger.info(\"+ CqlSession has been successfully closed\");         }     }          \/**      * Testing existence is useful for building correct semantics in the RESTful API. To evaluate existence find the      * table where confirmation number is partition key which is reservations_by_confirmation      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      true if the reservation exists, false if it does not      *\/     public boolean exists(String confirmationNumber) {         return cqlSession.execute(psExistReservation.bind(confirmationNumber))                          .getAvailableWithoutFetching() > 0;     }          \/**      * Similar to exists() but maps and parses results.      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      reservation if present or empty      *\/     @NonNull     public Optional&lt;Reservation> findByConfirmationNumber(@NonNull String confirmationNumber) {                  ResultSet resultSet = cqlSession.execute(psFindReservation.bind(confirmationNumber));                  \/\/ Hint: an empty result might not be an error as this method is sometimes used to check whether a         \/\/ reservation with this confirmation number exists         Row row = resultSet.one();         if (row == null) {             logger.debug(\"Unable to load reservation with confirmation number: \" + confirmationNumber);             return Optional.empty();         }                  \/\/ Hint: If there is a result, create a new reservation object and set the values         \/\/ Bonus: factor the logic to extract a reservation from a row into a separate method         \/\/ (you will reuse it again later in getAllReservations())         return Optional.of(mapRowToReservation(row));     }          \/**      * Create new entry in multiple tables for this reservation.      *      * @param reservation      *      current reservation object      * @return      *      confirmation number for the reservation      *            *\/      public String upsert(Reservation reservation) {         Objects.requireNonNull(reservation);         if (null == reservation.getConfirmationNumber()) {             \/\/ Generating a new reservation number if none has been provided             reservation.setConfirmationNumber(UUID.randomUUID().toString());         }         \/\/ Insert into 'reservations_by_hotel_date'         BoundStatement bsInsertReservationByHotel =                  psInsertReservationByHotelDate.bind(reservation.getHotelId(), reservation.getStartDate(),                         reservation.getEndDate(), reservation.getRoomNumber(), reservation.getConfirmationNumber(),                         reservation.getGuestId());         \/\/ Insert into 'reservations_by_confirmation'         BoundStatement bsInsertReservationByConfirmation =                  psInsertReservationByConfirmation.bind(reservation.getConfirmationNumber(), reservation.getHotelId(),                         reservation.getStartDate(), reservation.getEndDate(), reservation.getRoomNumber(),                         reservation.getGuestId());         BatchStatement batchInsertReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsInsertReservationByHotel)                     .addStatement(bsInsertReservationByConfirmation)                     .build();         cqlSession.execute(batchInsertReservation);          \/\/ TODO: Publish message to Kafka containing reservation          try {              String reservationJson = objectMapper.writeValueAsString(reservation);              \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)              \/\/ with the reservation confirmation number as the key, and the JSON string as the value              ProducerRecord&lt;String, String> record = null;              kafkaProducer.send(record);          } catch (Exception e) {              logger.warn(\"Error publishing reservation message to Kafka: {}\", e);          }          return reservation.getConfirmationNumber();     }      \/**      * We pick 'reservations_by_confirmation' table to list reservations      * BUT we could have used 'reservations_by_hotel_date' (as no key provided in request)      *        * @return      *      list containing all reservations      *\/     public List&lt;Reservation> findAll() {         return cqlSession.execute(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all().build())                   .all()                          \/\/ no paging we retrieve all objects                   .stream()                       \/\/ because we are good people                   .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                   .collect(Collectors.toList());  \/\/ Back to list objects     }            \/**      * Deleting a reservation.      *      * @param confirmationNumber      *      unique identifier for confirmation.      *\/     public boolean delete(String confirmationNumber) {          \/\/ Retrieving entire reservation in order to obtain the attributes we will need to delete from         \/\/ reservations_by_hotel_date table         Optional&lt;Reservation> reservationToDelete = this.findByConfirmationNumber(confirmationNumber);          if (reservationToDelete.isPresent()) {              \/\/ Delete from 'reservations_by_hotel_date'             Reservation reservation = reservationToDelete.get();             BoundStatement bsDeleteReservationByHotelDate =                     psDeleteReservationByHotelDate.bind(reservation.getHotelId(),                             reservation.getStartDate(), reservation.getRoomNumber());              \/\/ Delete from 'reservations_by_confirmation'             BoundStatement bsDeleteReservationByConfirmation =                     psDeleteReservationByConfirmation.bind(confirmationNumber);              BatchStatement batchDeleteReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsDeleteReservationByHotelDate)                     .addStatement(bsDeleteReservationByConfirmation)                     .build();             cqlSession.execute(batchDeleteReservation);              \/\/ TODO: Publish message to Kafka with empty payload to indicate deletion             \/\/ HINT: use the constructor ProducerRecord(String topic, K key, V value)             \/\/ with the reservation confirmation number as the key, and an empty string as the value             ProducerRecord&lt;String, String> record = null;             kafkaProducer.send(record);              return true;         }         return false;     }          \/**      * Search all reservation for an hotel id and LocalDate.      *      * @param hotelId      *      hotel identifier      * @param date      *      searched Date      * @return      *      list of reservations matching the search criteria      *\/     public List&lt;Reservation> findByHotelAndDate(String hotelId, LocalDate date) {         Objects.requireNonNull(hotelId);         Objects.requireNonNull(date);         return cqlSession.execute(psSearchReservation.bind(hotelId, date))                          .all()                          \/\/ no paging we retrieve all objects                          .stream()                       \/\/ because we are good people                          .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                          .collect(Collectors.toList());  \/\/ Back to list objects     }      \/**      * Utility method to marshal a row as expected Reservation Bean.      *      * @param row      *      current row from ResultSet      * @return      *      object      *\/     private Reservation mapRowToReservation(Row row) {         Reservation reservation = new Reservation();         reservation.setHotelId(row.getString(HOTEL_ID));         reservation.setConfirmationNumber(row.getString(CONFIRM_NUMBER));         reservation.setGuestId(row.getUuid(GUEST_ID));         reservation.setRoomNumber(row.getShort(ROOM_NUMBER));         reservation.setStartDate(row.getLocalDate(START_DATE));         reservation.setEndDate(row.getLocalDate(END_DATE));         return reservation;     }          \/**      * Create Keyspace and relevant tables as per defined in 'reservation.cql'      *\/     public void createReservationTables() {                  \/**          * Create TYPE 'Address' if not exists          *           * CREATE TYPE reservation.address (          *   street text,          *   city text,          *   state_or_province text,          *   postal_code text,          *   country text          * );          *\/         cqlSession.execute(                 createType(keyspaceName, TYPE_ADDRESS)                 .ifNotExists()                 .withField(STREET, DataTypes.TEXT)                 .withField(CITY, DataTypes.TEXT)                 .withField(STATE_PROVINCE, DataTypes.TEXT)                 .withField(POSTAL_CODE, DataTypes.TEXT)                 .withField(COUNTRY, DataTypes.TEXT)                 .build());         logger.debug(\"+ Type '{}' has been created (if needed)\", TYPE_ADDRESS.asInternal());                  \/**           * CREATE TABLE reservation.reservations_by_hotel_date (          *  hotel_id text,          *  start_date date,          *  end_date date,          *  room_number smallint,          *  confirm_number text,          *  guest_id uuid,          *  PRIMARY KEY ((hotel_id, start_date), room_number)          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                         .ifNotExists()                         .withPartitionKey(HOTEL_ID, DataTypes.TEXT)                         .withPartitionKey(START_DATE, DataTypes.DATE)                         .withClusteringColumn(ROOM_NUMBER, DataTypes.SMALLINT)                         .withColumn(END_DATE, DataTypes.DATE)                         .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                         .withColumn(GUEST_ID, DataTypes.UUID)                         .withClusteringOrder(ROOM_NUMBER, ClusteringOrder.ASC)                         .withComment(\"Q7. Find reservations by hotel and date\")                         .build());         logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_HOTEL_DATE.asInternal());                  \/**          * CREATE TABLE reservation.reservations_by_confirmation (          *   confirm_number text PRIMARY KEY,          *   hotel_id text,          *   start_date date,          *   end_date date,          *   room_number smallint,          *   guest_id uuid          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_CONFI)                 .ifNotExists()                 .withPartitionKey(CONFIRM_NUMBER, DataTypes.TEXT)                 .withColumn(HOTEL_ID, DataTypes.TEXT)                 .withColumn(START_DATE, DataTypes.DATE)                 .withColumn(END_DATE, DataTypes.DATE)                 .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                 .withColumn(GUEST_ID, DataTypes.UUID)                 .build());          logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_CONFI.asInternal());                    \/**           * CREATE TABLE reservation.reservations_by_guest (           *  guest_last_name text,           *  hotel_id text,           *  start_date date,           *  end_date date,           *  room_number smallint,           *  confirm_number text,           *  guest_id uuid,           *  PRIMARY KEY ((guest_last_name), hotel_id)           * );           *\/          cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_GUEST)                  .ifNotExists()                  .withPartitionKey(GUEST_LAST_NAME, DataTypes.TEXT)                  .withClusteringColumn(HOTEL_ID, DataTypes.TEXT)                  .withColumn(START_DATE, DataTypes.DATE)                  .withColumn(END_DATE, DataTypes.DATE)                  .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                  .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                  .withColumn(GUEST_ID, DataTypes.UUID)                  .withComment(\"Q8. Find reservations by guest name\")                  .build());           logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_GUEST.asInternal());                      \/**            * CREATE TABLE reservation.guests (            *   guest_id uuid PRIMARY KEY,            *   first_name text,            *   last_name text,            *   title text,            *   emails set&lt;text>,            *   phone_numbers list&lt;text>,            *   addresses map&lt;text, frozen&lt;address>>,            *   confirm_number text            * );            *\/           UserDefinedType  udtAddressType =                    cqlSession.getMetadata().getKeyspace(keyspaceName).get() \/\/ Retrieving KeySpaceMetadata                             .getUserDefinedType(TYPE_ADDRESS).get();        \/\/ Looking for UDT (extending DataType)           cqlSession.execute(createTable(keyspaceName, TABLE_GUESTS)                   .ifNotExists()                   .withPartitionKey(GUEST_ID, DataTypes.UUID)                   .withColumn(FIRSTNAME, DataTypes.TEXT)                   .withColumn(LASTNAME, DataTypes.TEXT)                   .withColumn(TITLE, DataTypes.TEXT)                   .withColumn(EMAILS, DataTypes.setOf(DataTypes.TEXT))                   .withColumn(PHONE_NUMBERS, DataTypes.listOf(DataTypes.TEXT))                   .withColumn(ADDRESSES, DataTypes.mapOf(DataTypes.TEXT, udtAddressType, true))                   .withColumn(CONFIRM_NUMBER, DataTypes.TEXT)                   .withComment(\"Q9. Find guest by ID\")                   .build());            logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_GUESTS.asInternal());            logger.info(\"Schema has been successfully initialized.\");     }      private void prepareStatements() {         if (psExistReservation == null) {             psExistReservation = cqlSession.prepare(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).column(CONFIRM_NUMBER)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psFindReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all()                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psSearchReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE).all()                                 .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                                 .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                                 .build());             psDeleteReservationByConfirmation = cqlSession.prepare(                                 deleteFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI)                                 .where(column(CONFIRM_NUMBER).isEqualTo(bindMarker(CONFIRM_NUMBER)))                                 .build());             psDeleteReservationByHotelDate = cqlSession.prepare(                     deleteFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                     .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                     .where(column(ROOM_NUMBER).isEqualTo(bindMarker(ROOM_NUMBER)))                     .build());             psInsertReservationByHotelDate = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             psInsertReservationByConfirmation = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_CONFI)                     .value(CONFIRM_NUMBER, bindMarker(CONFIRM_NUMBER))                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             logger.info(\"Statements have been successfully prepared.\");         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p><code>TODO<\/code> \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0443\u043d\u043a\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><code>TODO<\/code>: \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u0438\u043c\u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Kafka. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><code>TODO<\/code>: \u042d\u0442\u043e \u043e\u0431\u0437\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Kafka. \u0412 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f <code>ObjectMapper<\/code> \u0438 <code>KafkaProducer<\/code>.<\/p>\n<\/li>\n<li>\n<p><code>TODO<\/code>: \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 Kafka, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><code>TODO<\/code>: \u042d\u0442\u043e \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u041a\u0430\u0444\u043a\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 reservation. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>upsert()<\/code> \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0439\u0442\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 JSON.<\/p>\n<\/li>\n<li>\n<p><code>TODO<\/code>: \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f Kafka \u0441 \u043f\u0443\u0441\u0442\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435. \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <code>delete()<\/code> \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0431 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u043c \u043d\u0430\u0448 \u043a\u043e\u0434: <\/p>\n<details class=\"spoiler\">\n<summary>ReservationRepositorySolution.java<\/summary>\n<div class=\"spoiler__content\">\n<pre><code>\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * 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.  *\/ package dev.cassandraguide.repository;  import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom; import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createTable; import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createType; import static com.datastax.oss.driver.api.querybuilder.relation.Relation.column;  import java.time.LocalDate; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors;  import javax.annotation.PreDestroy;  import com.fasterxml.jackson.core.JsonProcessingException; import dev.cassandraguide.model.Reservation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Profile; import org.springframework.lang.NonNull; import org.springframework.stereotype.Repository;  import com.datastax.oss.driver.api.core.CqlIdentifier; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.cql.BatchStatement; import com.datastax.oss.driver.api.core.cql.BoundStatement; import com.datastax.oss.driver.api.core.cql.DefaultBatchType; import com.datastax.oss.driver.api.core.cql.PreparedStatement; import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; import com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder; import com.datastax.oss.driver.api.core.type.DataTypes; import com.datastax.oss.driver.api.core.type.UserDefinedType; import com.datastax.oss.driver.api.querybuilder.QueryBuilder;  \/\/ TODO: Review imports for publishing to Kafka import org.apache.kafka.clients.producer.*; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;  \/**  * The goal of this project is to provide a minimally functional implementation of a microservice   * that uses Apache Cassandra for its data storage. The reservation service is implemented as a   * RESTful service using Spring Boot.  *  * @author Jeff Carpenter, Cedrick Lunven  *\/ @Repository @Profile(\"!unit-test\") \/\/ When I do some 'unit-test' no connectivity to DB public class ReservationRepository {      \/** Logger for the class. *\/     private static final Logger logger = LoggerFactory.getLogger(ReservationRepository.class);          \/\/ Reservation Schema Constants     public static final CqlIdentifier TYPE_ADDRESS               = CqlIdentifier.fromCql(\"address\");     public static final CqlIdentifier TABLE_RESERVATION_BY_HOTEL_DATE =             CqlIdentifier.fromCql(\"reservations_by_hotel_date\");     public static final CqlIdentifier TABLE_RESERVATION_BY_CONFI = CqlIdentifier.fromCql(\"reservations_by_confirmation\");     public static final CqlIdentifier TABLE_RESERVATION_BY_GUEST = CqlIdentifier.fromCql(\"reservations_by_guest\");     public static final CqlIdentifier TABLE_GUESTS               = CqlIdentifier.fromCql(\"guests\");     public static final CqlIdentifier STREET                     = CqlIdentifier.fromCql(\"street\");     public static final CqlIdentifier CITY                       = CqlIdentifier.fromCql(\"city\");     public static final CqlIdentifier STATE_PROVINCE             = CqlIdentifier.fromCql(\"state_or_province\");     public static final CqlIdentifier POSTAL_CODE                = CqlIdentifier.fromCql(\"postal_code\");     public static final CqlIdentifier COUNTRY                    = CqlIdentifier.fromCql(\"country\");     public static final CqlIdentifier HOTEL_ID                   = CqlIdentifier.fromCql(\"hotel_id\");     public static final CqlIdentifier START_DATE                 = CqlIdentifier.fromCql(\"start_date\");     public static final CqlIdentifier END_DATE                   = CqlIdentifier.fromCql(\"end_date\");     public static final CqlIdentifier ROOM_NUMBER                = CqlIdentifier.fromCql(\"room_number\");     public static final CqlIdentifier CONFIRMATION_NUMBER        = CqlIdentifier.fromCql(\"confirmation_number\");     public static final CqlIdentifier GUEST_ID                   = CqlIdentifier.fromCql(\"guest_id\");     public static final CqlIdentifier GUEST_LAST_NAME            = CqlIdentifier.fromCql(\"guest_last_name\");     public static final CqlIdentifier FIRSTNAME                  = CqlIdentifier.fromCql(\"first_name\");     public static final CqlIdentifier LASTNAME                   = CqlIdentifier.fromCql(\"last_name\");     public static final CqlIdentifier TITLE                      = CqlIdentifier.fromCql(\"title\");     public static final CqlIdentifier EMAILS                     = CqlIdentifier.fromCql(\"emails\");     public static final CqlIdentifier PHONE_NUMBERS              = CqlIdentifier.fromCql(\"phone_numbers\");     public static final CqlIdentifier ADDRESSES                  = CqlIdentifier.fromCql(\"addresses\");          private PreparedStatement psExistReservation;     private PreparedStatement psFindReservation;     private PreparedStatement psInsertReservationByHotelDate;     private PreparedStatement psInsertReservationByConfirmation;     private PreparedStatement psDeleteReservationByHotelDate;     private PreparedStatement psDeleteReservationByConfirmation;     private PreparedStatement psSearchReservation;          \/** CqlSession holding metadata to interact with Cassandra. *\/     private CqlSession     cqlSession;     private CqlIdentifier  keyspaceName;      \/\/ TODO: Review variables used for publishing to Kafka     \/** KafkaProducer for publishing messages to Kafka. *\/     private KafkaProducer&lt;String, String> kafkaProducer;     private String kafkaTopicName;     private ObjectMapper objectMapper;          \/** External Initialization. *\/     public ReservationRepository(             @NonNull CqlSession cqlSession,              @Qualifier(\"keyspace\") @NonNull CqlIdentifier keyspaceName,             @NonNull KafkaProducer&lt;String, String> kafkaProducer,             @NonNull String kafkaTopicName) {         this.cqlSession   = cqlSession;         this.keyspaceName = keyspaceName;          \/\/ TODO: Review initialization of objects needed for publishing to Kafka         this.kafkaProducer = kafkaProducer;         this.kafkaTopicName = kafkaTopicName;          objectMapper = new ObjectMapper();         objectMapper.registerModule(new JavaTimeModule());         objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)         objectMapper.enable(SerializationFeature.INDENT_OUTPUT)          \/\/ Will create tables (if they do not exist)         createReservationTables();                  \/\/ Prepare Statements of reservation         prepareStatements();         logger.info(\"Application initialized.\");     }          \/**      * CqlSession is a stateful object handling TCP connections to nodes in the cluster.      * This operation properly closes sockets when the application is stopped      *\/     @PreDestroy     public void cleanup() {         if (null != cqlSession) {             cqlSession.close();             logger.info(\"+ CqlSession has been successfully closed\");         }     }          \/**      * Testing existence is useful for building correct semantics in the RESTful API. To evaluate existence find the      * table where confirmation number is partition key which is reservations_by_confirmation      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      true if the reservation exists, false if it does not      *\/     public boolean exists(String confirmationNumber) {         return cqlSession.execute(psExistReservation.bind(confirmationNumber))                          .getAvailableWithoutFetching() > 0;     }          \/**      * Similar to exists() but maps and parses results.      *       * @param confirmationNumber      *      unique identifier for confirmation      * @return      *      reservation if present or empty      *\/     @NonNull     public Optional&lt;Reservation> findByConfirmationNumber(@NonNull String confirmationNumber) {                  ResultSet resultSet = cqlSession.execute(psFindReservation.bind(confirmationNumber));                  \/\/ Hint: an empty result might not be an error as this method is sometimes used to check whether a         \/\/ reservation with this confirmation number exists         Row row = resultSet.one();         if (row == null) {             logger.debug(\"Unable to load reservation with confirmation number: \" + confirmationNumber);             return Optional.empty();         }                  \/\/ Hint: If there is a result, create a new reservation object and set the values         \/\/ Bonus: factor the logic to extract a reservation from a row into a separate method         \/\/ (you will reuse it again later in getAllReservations())         return Optional.of(mapRowToReservation(row));     }          \/**      * Create new entry in multiple tables for this reservation.      *      * @param reservation      *      current reservation object      * @return      *      confirmation number for the reservation      *            *\/      public String upsert(Reservation reservation) {         Objects.requireNonNull(reservation);         if (null == reservation.getConfirmationNumber()) {             \/\/ Generating a new reservation number if none has been provided             reservation.setConfirmationNumber(UUID.randomUUID().toString());         }         \/\/ Insert into 'reservations_by_hotel_date'         BoundStatement bsInsertReservationByHotel =                  psInsertReservationByHotelDate.bind(reservation.getHotelId(), reservation.getStartDate(),                         reservation.getEndDate(), reservation.getRoomNumber(), reservation.getConfirmationNumber(),                         reservation.getGuestId());         \/\/ Insert into 'reservations_by_confirmation'         BoundStatement bsInsertReservationByConfirmation =                  psInsertReservationByConfirmation.bind(reservation.getConfirmationNumber(), reservation.getHotelId(),                         reservation.getStartDate(), reservation.getEndDate(), reservation.getRoomNumber(),                         reservation.getGuestId());         BatchStatement batchInsertReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsInsertReservationByHotel)                     .addStatement(bsInsertReservationByConfirmation)                     .build();         cqlSession.execute(batchInsertReservation);          \/\/ TODO: Publish message to Kafka containing reservation          try {              String reservationJson = objectMapper.writeValueAsString(reservation);              ProducerRecord&lt;String, String> record = new ProducerRecord&lt;>(kafkaTopicName, reservation.getConfirmationNumber(), reservationJson);              kafkaProducer.send(record);          } catch (Exception e) {              logger.warn(\"Error publishing reservation message to Kafka: {}\", e);          }          return reservation.getConfirmationNumber();     }      \/**      * We pick 'reservations_by_confirmation' table to list reservations      * BUT we could have used 'reservations_by_hotel_date' (as no key provided in request)      *        * @return      *      list containing all reservations      *\/     public List&lt;Reservation> findAll() {         return cqlSession.execute(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all().build())                   .all()                          \/\/ no paging we retrieve all objects                   .stream()                       \/\/ because we are good people                   .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                   .collect(Collectors.toList());  \/\/ Back to list objects     }            \/**      * Deleting a reservation.      *      * @param confirmationNumber      *      unique identifier for confirmation.      *\/     public boolean delete(String confirmationNumber) {          \/\/ Retrieving entire reservation in order to obtain the attributes we will need to delete from         \/\/ reservations_by_hotel_date table         Optional&lt;Reservation> reservationToDelete = this.findByConfirmationNumber(confirmationNumber);          if (reservationToDelete.isPresent()) {              \/\/ Delete from 'reservations_by_hotel_date'             Reservation reservation = reservationToDelete.get();             BoundStatement bsDeleteReservationByHotelDate =                     psDeleteReservationByHotelDate.bind(reservation.getHotelId(),                             reservation.getStartDate(), reservation.getRoomNumber());              \/\/ Delete from 'reservations_by_confirmation'             BoundStatement bsDeleteReservationByConfirmation =                     psDeleteReservationByConfirmation.bind(confirmationNumber);              BatchStatement batchDeleteReservation = BatchStatement                     .builder(DefaultBatchType.LOGGED)                     .addStatement(bsDeleteReservationByHotelDate)                     .addStatement(bsDeleteReservationByConfirmation)                     .build();             cqlSession.execute(batchDeleteReservation);              \/\/ TODO: Publish message to Kafka with empty payload to indicate deletion             ProducerRecord&lt;String, String> record = new ProducerRecord&lt;>(kafkaTopicName, reservation.getConfirmationNumber(), \"\");             kafkaProducer.send(record);              return true;         }         return false;     }          \/**      * Search all reservation for an hotel id and LocalDate.      *      * @param hotelId      *      hotel identifier      * @param date      *      searched Date      * @return      *      list of reservations matching the search criteria      *\/     public List&lt;Reservation> findByHotelAndDate(String hotelId, LocalDate date) {         Objects.requireNonNull(hotelId);         Objects.requireNonNull(date);         return cqlSession.execute(psSearchReservation.bind(hotelId, date))                          .all()                          \/\/ no paging we retrieve all objects                          .stream()                       \/\/ because we are good people                          .map(this::mapRowToReservation) \/\/ Mapping row as Reservation                          .collect(Collectors.toList());  \/\/ Back to list objects     }      \/**      * Utility method to marshal a row as expected Reservation Bean.      *      * @param row      *      current row from ResultSet      * @return      *      object      *\/     private Reservation mapRowToReservation(Row row) {         Reservation reservation = new Reservation();         reservation.setHotelId(row.getString(HOTEL_ID));         reservation.setConfirmationNumber(row.getString(CONFIRMATION_NUMBER));         reservation.setGuestId(row.getUuid(GUEST_ID));         reservation.setRoomNumber(row.getShort(ROOM_NUMBER));         reservation.setStartDate(row.getLocalDate(START_DATE));         reservation.setEndDate(row.getLocalDate(END_DATE));         return reservation;     }          \/**      * Create Keyspace and relevant tables as per defined in 'reservation.cql'      *\/     public void createReservationTables() {                  \/**          * Create TYPE 'Address' if not exists          *           * CREATE TYPE reservation.address (          *   street text,          *   city text,          *   state_or_province text,          *   postal_code text,          *   country text          * );          *\/         cqlSession.execute(                 createType(keyspaceName, TYPE_ADDRESS)                 .ifNotExists()                 .withField(STREET, DataTypes.TEXT)                 .withField(CITY, DataTypes.TEXT)                 .withField(STATE_PROVINCE, DataTypes.TEXT)                 .withField(POSTAL_CODE, DataTypes.TEXT)                 .withField(COUNTRY, DataTypes.TEXT)                 .build());         logger.debug(\"+ Type '{}' has been created (if needed)\", TYPE_ADDRESS.asInternal());                  \/**           * CREATE TABLE reservation.reservations_by_hotel_date (          *  hotel_id text,          *  start_date date,          *  end_date date,          *  room_number smallint,          *  confirmation_number text,          *  guest_id uuid,          *  PRIMARY KEY ((hotel_id, start_date), room_number)          * ) WITH comment = 'Q7. Find reservations by hotel and date';          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                         .ifNotExists()                         .withPartitionKey(HOTEL_ID, DataTypes.TEXT)                         .withPartitionKey(START_DATE, DataTypes.DATE)                         .withClusteringColumn(ROOM_NUMBER, DataTypes.SMALLINT)                         .withColumn(END_DATE, DataTypes.DATE)                         .withColumn(CONFIRMATION_NUMBER, DataTypes.TEXT)                         .withColumn(GUEST_ID, DataTypes.UUID)                         .withClusteringOrder(ROOM_NUMBER, ClusteringOrder.ASC)                         .withComment(\"Q7. Find reservations by hotel and date\")                         .build());         logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_HOTEL_DATE.asInternal());                  \/**          * CREATE TABLE reservation.reservations_by_confirmation (          *   confirmation_number text PRIMARY KEY,          *   hotel_id text,          *   start_date date,          *   end_date date,          *   room_number smallint,          *   guest_id uuid          * );          *\/         cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_CONFI)                 .ifNotExists()                 .withPartitionKey(CONFIRMATION_NUMBER, DataTypes.TEXT)                 .withColumn(HOTEL_ID, DataTypes.TEXT)                 .withColumn(START_DATE, DataTypes.DATE)                 .withColumn(END_DATE, DataTypes.DATE)                 .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                 .withColumn(GUEST_ID, DataTypes.UUID)                 .build());          logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_CONFI.asInternal());                    \/**           * CREATE TABLE reservation.reservations_by_guest (           *  guest_last_name text,           *  hotel_id text,           *  start_date date,           *  end_date date,           *  room_number smallint,           *  confirmation_number text,           *  guest_id uuid,           *  PRIMARY KEY ((guest_last_name), hotel_id)           * ) WITH comment = 'Q8. Find reservations by guest name';           *\/          cqlSession.execute(createTable(keyspaceName, TABLE_RESERVATION_BY_GUEST)                  .ifNotExists()                  .withPartitionKey(GUEST_LAST_NAME, DataTypes.TEXT)                  .withClusteringColumn(HOTEL_ID, DataTypes.TEXT)                  .withColumn(START_DATE, DataTypes.DATE)                  .withColumn(END_DATE, DataTypes.DATE)                  .withColumn(ROOM_NUMBER, DataTypes.SMALLINT)                  .withColumn(CONFIRMATION_NUMBER, DataTypes.TEXT)                  .withColumn(GUEST_ID, DataTypes.UUID)                  .withComment(\"Q8. Find reservations by guest name\")                  .build());           logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_RESERVATION_BY_GUEST.asInternal());                      \/**            * CREATE TABLE reservation.guests (            *   guest_id uuid PRIMARY KEY,            *   first_name text,            *   last_name text,            *   title text,            *   emails set&lt;text>,            *   phone_numbers list&lt;text>,            *   addresses map&lt;text, frozen&lt;address>>,            *   confirmation_number text            * ) WITH comment = 'Q9. Find guest by ID';            *\/           UserDefinedType  udtAddressType =                    cqlSession.getMetadata().getKeyspace(keyspaceName).get() \/\/ Retrieving KeySpaceMetadata                             .getUserDefinedType(TYPE_ADDRESS).get();        \/\/ Looking for UDT (extending DataType)           cqlSession.execute(createTable(keyspaceName, TABLE_GUESTS)                   .ifNotExists()                   .withPartitionKey(GUEST_ID, DataTypes.UUID)                   .withColumn(FIRSTNAME, DataTypes.TEXT)                   .withColumn(LASTNAME, DataTypes.TEXT)                   .withColumn(TITLE, DataTypes.TEXT)                   .withColumn(EMAILS, DataTypes.setOf(DataTypes.TEXT))                   .withColumn(PHONE_NUMBERS, DataTypes.listOf(DataTypes.TEXT))                   .withColumn(ADDRESSES, DataTypes.mapOf(DataTypes.TEXT, udtAddressType, true))                   .withColumn(CONFIRMATION_NUMBER, DataTypes.TEXT)                   .withComment(\"Q9. Find guest by ID\")                   .build());            logger.debug(\"+ Table '{}' has been created (if needed)\", TABLE_GUESTS.asInternal());            logger.info(\"Schema has been successfully initialized.\");     }      private void prepareStatements() {         if (psExistReservation == null) {             psExistReservation = cqlSession.prepare(selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).column(CONFIRMATION_NUMBER)                                 .where(column(CONFIRMATION_NUMBER).isEqualTo(bindMarker(CONFIRMATION_NUMBER)))                                 .build());             psFindReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI).all()                                 .where(column(CONFIRMATION_NUMBER).isEqualTo(bindMarker(CONFIRMATION_NUMBER)))                                 .build());             psSearchReservation = cqlSession.prepare(                                 selectFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE).all()                                 .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                                 .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                                 .build());             psDeleteReservationByConfirmation = cqlSession.prepare(                                 deleteFrom(keyspaceName, TABLE_RESERVATION_BY_CONFI)                                 .where(column(CONFIRMATION_NUMBER).isEqualTo(bindMarker(CONFIRMATION_NUMBER)))                                 .build());             psDeleteReservationByHotelDate = cqlSession.prepare(                     deleteFrom(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .where(column(HOTEL_ID).isEqualTo(bindMarker(HOTEL_ID)))                     .where(column(START_DATE).isEqualTo(bindMarker(START_DATE)))                     .where(column(ROOM_NUMBER).isEqualTo(bindMarker(ROOM_NUMBER)))                     .build());             psInsertReservationByHotelDate = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_HOTEL_DATE)                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(CONFIRMATION_NUMBER, bindMarker(CONFIRMATION_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             psInsertReservationByConfirmation = cqlSession.prepare(QueryBuilder.insertInto(keyspaceName, TABLE_RESERVATION_BY_CONFI)                     .value(CONFIRMATION_NUMBER, bindMarker(CONFIRMATION_NUMBER))                     .value(HOTEL_ID, bindMarker(HOTEL_ID))                     .value(START_DATE, bindMarker(START_DATE))                     .value(END_DATE, bindMarker(END_DATE))                     .value(ROOM_NUMBER, bindMarker(ROOM_NUMBER))                     .value(GUEST_ID, bindMarker(GUEST_ID))                     .build());             logger.info(\"Statements have been successfully prepared.\");         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0442\u0435\u0441\u0442\u0430\u043c.<\/p>\n<p>\u0421\u043b\u0443\u0436\u0431\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0442\u0435\u0441\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 Cassandra, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0432 Docker, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0446\u0435\u043b\u0435\u0439 \u0442\u0435\u0441\u0442\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0443\u0437\u0435\u043b Cassandra:<\/p>\n<p><code>kill `cat \/tmp\/cassandra-pid`<\/code> <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Maven:<\/p>\n<p><code>mvn test<\/code><\/p>\n<p>\u041c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Apache Cassandra \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Apache Kafka.<\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0430 \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/TkHo\/\">Software Architect<\/a>. \u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u043a\u0430 \u043f\u043e \u0442\u0435\u043c\u0435 &#171;\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e &#171;\u0421\u043e\u043f\u0440\u043e\u0432\u043e\u0436\u0434\u0430\u0435\u043c\u043e\u0441\u0442\u044c&#187; \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 k8s&#187;.<\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/otus.pw\/TkHo\/\">\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0443\u0440\u043e\u043a \u0438 \u0443\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/722278\/\"> https:\/\/habr.com\/ru\/articles\/722278\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<div class=\"persona\" persona=\"true\">\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0420\u0443\u0441\u0442\u0435\u043c \u0413\u0430\u043b\u0438\u0435\u0432<\/h5>\n<p>IBM Senior DevOps Engineer &amp; Integration Architect  <\/p>\n<\/div>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Apache Cassandra \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Apache Kafka.<\/p>\n<p>\u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Reservation Service. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u0435\u0440\u0438\u044e \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0439 \u043f\u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0447\u0442\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Cassandra \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0443\u0436\u0431\u044b \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u00abCassandra: \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Java-\u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax\u00bb. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u043b\u0443\u0436\u0431\u044b \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/github.com\/jeffreyscarpenter\/reservation-service\">\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 GitHub<\/a>.  <\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0421\u043b\u0443\u0436\u0431\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>Cassandra \u0438 Kafka \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430\u0445, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435. \u0412 \u044d\u0442\u043e\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0441\u043b\u0443\u0436\u0431\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 API \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 Cassandra \u0441\u043b\u0443\u0436\u0431\u0430 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u0442\u043e\u043f\u0438\u043a reservation \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 Kafka.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0441\u043b\u0443\u0436\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0442\u043e\u043f\u0438\u043a reservation \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435: \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0443\u0436\u0431\u0430 \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u043d\u0432\u0435\u043d\u0442\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0434\u0430\u0442\u044b \u043a\u0430\u043a \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435, \u0438\u043b\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u043b\u0443\u0436\u0431\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0441 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u0433\u043e\u0441\u0442\u044e \u0437\u0430 \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u044d\u0442\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u041a\u0430\u0441\u0441\u0430\u043d\u0434\u0440\u0430 \u0438 \u041a\u0430\u0444\u043a\u0430 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u043e\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0441\u043b\u0443\u0436\u0431\u044b \u0431\u0440\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p><strong><br \/><\/strong>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 Reservation Service \u0441 GitHub \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0435\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439:<\/p>\n<p><code>git clone -b kafka<\/code> <a href=\"https:\/\/github.com\/jeffreyscarpenter\/reservation-service\"><u>https:\/\/github.com\/jeffreyscarpenter\/reservation-service<\/u><\/p>\n<p><\/a>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u043e, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <code>reservation_service<\/code>.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0445\u0435\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e \u043f\u0443\u0442\u0438 <code>reservation-service\/src\/main\/resources\/reservation.cql<\/code>:<\/p>\n<pre><code class=\"java\">\/*  * Copyright (C) 2016-2020 Jeff Carpenter  *\/  \/* This file contains a slightly modified version of the \"reservation\" keyspace and table definitions  * for the example defined in Chapter 5 of Cassandra: The Definitive Guide, 2nd and 3nd Editions.  * The changes are to facilitate development exercises.  *\/  CREATE KEYSPACE reservation     WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};  CREATE TABLE reservation.reservations_by_hotel_date (     hotel_id text,     start_date date,     end_date date,     room_number smallint,     confirm_number text,     guest_id uuid,     PRIMARY KEY ((hotel_id, start_date), room_number) );  CREATE TABLE reservation.reservations_by_confirmation (     confirm_number text PRIMARY KEY,     hotel_id text,     start_date date,     end_date date,     room_number smallint,     guest_id uuid );  \/*  The following tables are provided for completeness with the book text, but they are not used in the current  implementation of the Reservation Service  *\/  CREATE TABLE reservation.reservations_by_guest (     guest_last_name text,     hotel_id text,     start_date date,     end_date date,     room_number smallint,     confirm_number text,     guest_id uuid,     PRIMARY KEY ((guest_last_name), hotel_id) );  CREATE TYPE reservation.address (     street text,     city text,     state_or_province text,     postal_code text,     country text );  CREATE TABLE reservation.guests (     guest_id uuid PRIMARY KEY,     first_name text,     last_name text,     title text,     emails set&lt;text>,     phone_numbers list&lt;text>,     addresses map&lt;text, frozen&lt;address>> );<\/code><\/pre>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u0430 DataStax Java \u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a Kafka \u043f\u043e \u043f\u0443\u0442\u0438 <code>reservation-service\/pom.xml<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?> &lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"> &lt;modelVersion>4.0.0&lt;\/modelVersion>  &lt;groupId>com.cassandraguide&lt;\/groupId> &lt;artifactId>reservation-service&lt;\/artifactId> &lt;version>1.0.0&lt;\/version> &lt;packaging>jar&lt;\/packaging>  &lt;name>reservation-service&lt;\/name> &lt;description>Demo service using Cassandra driver and Spring Boot&lt;\/description>  &lt;parent> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-parent&lt;\/artifactId> &lt;version>2.2.6.RELEASE&lt;\/version> &lt;relativePath \/> &lt;\/parent>  &lt;properties> &lt;java.version>11&lt;\/java.version> &lt;swagger.version>2.9.2&lt;\/swagger.version> &lt;junit-jupiter.version>5.4.2&lt;\/junit-jupiter.version> &lt;junit-platform.version>1.7.0-M1&lt;\/junit-platform.version> &lt;oss-java-driver.version>4.5.1&lt;\/oss-java-driver.version> &lt;kafka-client.version>2.5.0&lt;\/kafka-client.version> &lt;testcontainers.version>1.14.1&lt;\/testcontainers.version>  &lt;version.maven.plugin.compiler>3.8.0&lt;\/version.maven.plugin.compiler> &lt;project.build.sourceEncoding>UTF-8&lt;\/project.build.sourceEncoding> &lt;start-class>dev.cassandraguide.ReservationServiceApp&lt;\/start-class> &lt;dockerfile-maven-version>1.4.13&lt;\/dockerfile-maven-version>  &lt;\/properties>  &lt;dependencies>  &lt;!-- Create a RESTFul Service --> &lt;dependency> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-web&lt;\/artifactId> &lt;\/dependency>  &lt;!-- Document for REST Service --> &lt;dependency> &lt;groupId>io.springfox&lt;\/groupId> &lt;artifactId>springfox-swagger2&lt;\/artifactId> &lt;version>${swagger.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>io.springfox&lt;\/groupId> &lt;artifactId>springfox-swagger-ui&lt;\/artifactId> &lt;version>${swagger.version}&lt;\/version> &lt;\/dependency>  &lt;!-- Cassandra Driver --> &lt;dependency> &lt;groupId>com.datastax.oss&lt;\/groupId> &lt;artifactId>java-driver-core&lt;\/artifactId> &lt;version>${oss-java-driver.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>com.datastax.oss&lt;\/groupId> &lt;artifactId>java-driver-query-builder&lt;\/artifactId> &lt;version>${oss-java-driver.version}&lt;\/version> &lt;\/dependency>  &lt;dependency> &lt;groupId>org.apache.kafka&lt;\/groupId> &lt;artifactId>kafka-clients&lt;\/artifactId> &lt;version>${kafka-client.version}&lt;\/version> &lt;\/dependency>  &lt;dependency> &lt;groupId>org.apache.commons&lt;\/groupId> &lt;artifactId>commons-lang3&lt;\/artifactId> &lt;\/dependency> &lt;!-- Provides JSON serialization\/deserialization for date\/time types --> &lt;dependency> &lt;groupId>com.fasterxml.jackson.datatype&lt;\/groupId> &lt;artifactId>jackson-datatype-jsr310&lt;\/artifactId> &lt;\/dependency>  &lt;!-- Tests --> &lt;dependency> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-starter-test&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;exclusions> &lt;exclusion> &lt;groupId>junit&lt;\/groupId> &lt;artifactId>junit&lt;\/artifactId> &lt;\/exclusion> &lt;\/exclusions> &lt;\/dependency> &lt;!-- Junit 5 --> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-api&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-engine&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.jupiter&lt;\/groupId> &lt;artifactId>junit-jupiter-params&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-engine&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-launcher&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-runner&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;dependency> &lt;groupId>org.junit.platform&lt;\/groupId> &lt;artifactId>junit-platform-console-standalone&lt;\/artifactId> &lt;version>${junit-platform.version}&lt;\/version> &lt;scope>test&lt;\/scope> &lt;\/dependency> &lt;!-- Test against Docker Containers --> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>cassandra&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>testcontainers&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;dependency> &lt;groupId>org.testcontainers&lt;\/groupId> &lt;artifactId>kafka&lt;\/artifactId> &lt;scope>test&lt;\/scope> &lt;version>${testcontainers.version}&lt;\/version> &lt;\/dependency> &lt;!-- Add driver keys to spring-boot config file --> &lt;dependency>            &lt;groupId>org.springframework.boot&lt;\/groupId>            &lt;artifactId>spring-boot-configuration-processor&lt;\/artifactId>            &lt;optional>true&lt;\/optional>         &lt;\/dependency>          &lt;\/dependencies>  &lt;build> &lt;plugins> &lt;plugin> &lt;groupId>org.springframework.boot&lt;\/groupId> &lt;artifactId>spring-boot-maven-plugin&lt;\/artifactId> &lt;configuration> &lt;fork>true&lt;\/fork> &lt;mainClass>${start-class}&lt;\/mainClass> &lt;\/configuration> &lt;executions> &lt;execution> &lt;goals> &lt;goal>repackage&lt;\/goal> &lt;\/goals> &lt;\/execution> &lt;\/executions> &lt;\/plugin>             &lt;plugin>                 &lt;groupId>org.apache.maven.plugins&lt;\/groupId>                 &lt;artifactId>maven-compiler-plugin&lt;\/artifactId>                 &lt;configuration>                     &lt;source>${java.version}&lt;\/source>                     &lt;target>${java.version}&lt;\/target> &lt;\/configuration>             &lt;\/plugin>  &lt;plugin> &lt;groupId>com.spotify&lt;\/groupId> &lt;artifactId>dockerfile-maven-plugin&lt;\/artifactId> &lt;version>${dockerfile-maven-version}&lt;\/version> &lt;configuration> &lt;repository>reservation-service&lt;\/repository> &lt;tag>${project.version}&lt;\/tag> &lt;buildArgs> &lt;JAR_FILE>${project.build.finalName}.jar&lt;\/JAR_FILE> &lt;\/buildArgs> &lt;\/configuration> &lt;\/plugin>         &lt;\/plugins> &lt;\/build>  &lt;\/project> <\/code><\/pre>\n<p>\u0412 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Java, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0442\u0430\u043a\u0436\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c:<\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0432 HTTP API, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432 Cassandra \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0432 \u0442\u0435\u043c\u0435 Kafka r<code>eservation-service\/src\/main\/java\/dev\/cassandraguide\/model\/Reservation.java<\/code>:<\/p>\n<pre><code class=\"java\">\/*  * Copyright (C) 2017-2020 Jeff Carpenter  *  * Licensed under the Apache License, Version 2.0 (the \"License\");  * you may not use this file except in compliance with the License.  *<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-383279","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=383279"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383279\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}