SlideShare a Scribd company logo
1 of 35
Introduction to Kafka
with Spring Integration
Introduction to Kafka with Spring
Integration
• Kafka (Mihail Yordanov)
• Spring integration (Borislav Markov)
• Students Example (Mihail & Borislav)
• Conclusion
Motivation
• Real time data being continuously generated
• Producers and consumers relationships
• Streaming systems
• Messaging systems
Apache Kafka
• Developed by LinkedIn
• “We built Apache Kafka at LinkedIn with a specific
purpose in mind: to serve as a central repository of
data streams.” - Jay Kreps
• Kafka improvements
– Transporting data between systems
– Richer analytical processing
• “A publish-subscribe messaging system rethought as a
distributed commit log”
Kafka Vocabulary
• Brokers
• Producers
• Consumers
• “A publish-subscribe messaging system
rethought as a distributed commit log”
Kafka Vocabulary
• Topics
• Partitions
• “A publish-subscribe messaging system rethought
as a distributed commit log”
Kafka Speed
Kafka Speed
Kafka Speed
Consumer groups
• Definition - “A publish-subscribe messaging
system rethought as a distributed commit log”
• Publish - Subscribe
• Queueing
Spring Integration
• Spring Integration enables lightweight
messaging
• Supports integration with external systems via
declarative adapters
• Primary goal is to provide a simple model for
building enterprise integration solutions
• Separation of concerns
• Maintainable, testable code
Features
• Implementation of most of the Enterprise Integration Patterns
• Endpoint
• Channel (Point-to-point and Publish/Subscribe)
• Aggregator
• Filter
• Transformer
• Control Bus
• …
• Integration with External Systems
• ReST/HTTP
• ...
The theory...
The patterns can be found at
http://www.enterpriseintegrationpatterns.com/patterns/messag
ing/index.html
Message
• Messages are objects that carry information between two applications
• They are constructed by the producer and they are consumed/deconstructed at
the consumer/subscriber
• Message consists of:
– payload
– header
public interface Message<T> {
T getPayload();
MessageHeaders getHeaders();
}
Message endpoints
Common endpoints:
• Service Activator - invokes a method on a
bean
• Message Bridge - couples different
messaging modes/adapters. Example: (P2P
with Publish/Subscribe)
• Message Enricher - enrich the incoming
message with additional information.
– Header Enricher - add header
attributes
– Payload Enricher - enrich payload
Message endpoints (continued)
• Gateway - Used when we don’t have knowledge for the
messaging system.
– Synchronous Gateway - void or returns T
– Asynchronous Gateway - returns Future<T>
• Delayer - introduce delay between sender and receiver
• Consumers
– Polling Consumers - poll messages in a timely fashion
– Polling Using Triggers - poll messages with PeriodicTrigger
and with CronTrigger
– Event-Driven Consumers - they wait for someone to
deliver the message (framework’s responsibility)
Message endpoints (continued)
• Channel Adapter - endpoint that connects a Message Channel
to some other system or transport.
–inbound
–outbound
Message Channels
• interface MessageChannel
– boolean send(Message<?> message);
– boolean send(Message<?> message, long timeout);
• Point-to-Point Mode -> PollableChannel
– Message<?> receive();
– Message<?> receive(long timeout);
• Publish/Subscribe Mode -> SubscribableChannel
– boolean subscribe(MessageHandler handler);
– boolean unsubscribe(MessageHandler handler);
Message Channels(continued)
•Queue Channel - has capacity
•Priority Channel - queue channel with
prioritization
•PublishSubscribe Channel
•DirectChannel - mixed type P2P and
Pub/Sub
Message Channels(continued)
Flow components
• Filters
– Custom filters are tied to the framework, can
be bean method returning boolean
– Framework MessageSelector - use of method
boolean accept(Message m)
– Using annotation - @Filter
• Routers
– PayloadTypeRouter
– HeaderValueRouter
– Custom Routers - any bean method can be
router, the result will be the channel name.
– Recipient List Router - the message goes to all
statically defined channels
Flow components (continued...)
• Splitters - splits a message into pieces
– Custom splitters - any bean method;
– Framework AbstractMessageSplitter - use of method Object splitMessage(Message
m);
– Using annotation - @Splitter ;
• Aggregator
– assemble multiple messages to create a single parent message
– Complex task - all messages of a set have to arrive before aggregators can start work
– CorrelationStrategy - defines the key for grouping of the messages, the default
grouping is based on CORRELATION_ID
– ReleaseStrategy - dictates at which point the group of messages should be sent or
released for aggregation. Default is SequenceSizeReleazeStrategy
– Message Store - aggregators hold messages until all of them arrived. Options are:
• in-memory
• external database
• Resequencer - fix order of the messages(work on SEQUENCE_NUMBER)
Transformers
• Built-in transformers
– String Transformers - invokes toString() method of the payload
– Map Transformers - transformes POJO to a name-value pair of
Map
– Serializing and Deserializing Transformers - converts payload
to byte array
– JSON Transformers - object-to-json converts POJO to readable
JSON format; json-to-object transformer needs additional
property “type”
– XML Transformers - requires Spring OXM (Object-to-XML);
org.springframework.oxm.Marshaller/Unmarshaller
Transformers(continued...)
• Built-in transformers
– XPath Transformers - decodes
XML using XPath expressions, ex.:
xpath-
expression=”/mytag/@prop”
• Custom Transformers - can be any
spring bean method
• Using @Transformer
Students Example
• Example application will demo usage
of Kafka and Spring Integration
• App is built with maven
• Ideal candidate for Microservice
• Idea: takes students from outside and
calculates their average score
Maven dependencies
Project Structure
• Package “api” – POJO models
• Package “config” – beans with
factory methods
• Package “service” – the
business logic
• Folder “resources” –
application.properties
Spring Integration DSL
Students Example
Service activator
Running the app and giving some
inputs
Check the logs
Conclusion
Why Kafka and Spring ?
• Easy for microservices
• Clean and testable code
• Widely adopted technologies
• Easy to be dockerized
Introduction to Kafka with Spring Integration

More Related Content

What's hot

What's hot (20)

Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트) 마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 
Amazon OpenSearch Deep dive - 내부구조, 성능최적화 그리고 스케일링
Amazon OpenSearch Deep dive - 내부구조, 성능최적화 그리고 스케일링Amazon OpenSearch Deep dive - 내부구조, 성능최적화 그리고 스케일링
Amazon OpenSearch Deep dive - 내부구조, 성능최적화 그리고 스케일링
 
"API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T...
"API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T..."API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T...
"API Design: From User Need to Finished Spec" by Andrew Jordan, ex-Product @T...
 
RabbitMQ
RabbitMQ RabbitMQ
RabbitMQ
 
AWS 네트워크 보안을 위한 계층별 보안 구성 모범 사례 – 조이정, AWS 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
AWS 네트워크 보안을 위한 계층별 보안 구성 모범 사례 – 조이정, AWS 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집AWS 네트워크 보안을 위한 계층별 보안 구성 모범 사례 – 조이정, AWS 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
AWS 네트워크 보안을 위한 계층별 보안 구성 모범 사례 – 조이정, AWS 솔루션즈 아키텍트:: AWS 온라인 이벤트 – 클라우드 보안 특집
 
Stream processing using Kafka
Stream processing using KafkaStream processing using Kafka
Stream processing using Kafka
 
Apache Kafka
Apache KafkaApache Kafka
Apache Kafka
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Observability in Java: Getting Started with OpenTelemetry
Observability in Java: Getting Started with OpenTelemetryObservability in Java: Getting Started with OpenTelemetry
Observability in Java: Getting Started with OpenTelemetry
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
 
Apache Kafka and ksqlDB in Action: Let's Build a Streaming Data Pipeline! (Ro...
Apache Kafka and ksqlDB in Action: Let's Build a Streaming Data Pipeline! (Ro...Apache Kafka and ksqlDB in Action: Let's Build a Streaming Data Pipeline! (Ro...
Apache Kafka and ksqlDB in Action: Let's Build a Streaming Data Pipeline! (Ro...
 
Kubernetes monitoring using prometheus stack
Kubernetes monitoring using prometheus stackKubernetes monitoring using prometheus stack
Kubernetes monitoring using prometheus stack
 
서비스 모니터링 구현 사례 공유 - Realtime log monitoring platform-PMon을 ...
서비스 모니터링 구현 사례 공유 - Realtime log monitoring platform-PMon을 ...서비스 모니터링 구현 사례 공유 - Realtime log monitoring platform-PMon을 ...
서비스 모니터링 구현 사례 공유 - Realtime log monitoring platform-PMon을 ...
 
Service discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring CloudService discovery with Eureka and Spring Cloud
Service discovery with Eureka and Spring Cloud
 
Avro Tutorial - Records with Schema for Kafka and Hadoop
Avro Tutorial - Records with Schema for Kafka and HadoopAvro Tutorial - Records with Schema for Kafka and Hadoop
Avro Tutorial - Records with Schema for Kafka and Hadoop
 

Viewers also liked

Viewers also liked (8)

Microservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloudMicroservices - java ee vs spring boot and spring cloud
Microservices - java ee vs spring boot and spring cloud
 
Introduction To Functional Reactive Programming Poznan
Introduction To Functional Reactive Programming PoznanIntroduction To Functional Reactive Programming Poznan
Introduction To Functional Reactive Programming Poznan
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Spring integration with the Java DSL
Spring integration with the Java DSLSpring integration with the Java DSL
Spring integration with the Java DSL
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event Sourcing
 
Integration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices ArchitecturesIntegration Patterns and Anti-Patterns for Microservices Architectures
Integration Patterns and Anti-Patterns for Microservices Architectures
 
Scaling wix with microservices architecture devoxx London 2015
Scaling wix with microservices architecture devoxx London 2015Scaling wix with microservices architecture devoxx London 2015
Scaling wix with microservices architecture devoxx London 2015
 

Similar to Introduction to Kafka with Spring Integration

Real time machine learning visualization with spark -- Hadoop Summit 2016
Real time machine learning visualization with spark -- Hadoop Summit 2016Real time machine learning visualization with spark -- Hadoop Summit 2016
Real time machine learning visualization with spark -- Hadoop Summit 2016
Chester Chen
 
apachekafka-160907180205.pdf
apachekafka-160907180205.pdfapachekafka-160907180205.pdf
apachekafka-160907180205.pdf
TarekHamdi8
 
quickguide-einnovator-11-spring-integration
quickguide-einnovator-11-spring-integrationquickguide-einnovator-11-spring-integration
quickguide-einnovator-11-spring-integration
jorgesimao71
 

Similar to Introduction to Kafka with Spring Integration (20)

Spring integration
Spring integrationSpring integration
Spring integration
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Hadoop Ecosystem and Low Latency Streaming Architecture
Hadoop Ecosystem and Low Latency Streaming ArchitectureHadoop Ecosystem and Low Latency Streaming Architecture
Hadoop Ecosystem and Low Latency Streaming Architecture
 
Real Time Machine Learning Visualization with Spark
Real Time Machine Learning Visualization with SparkReal Time Machine Learning Visualization with Spark
Real Time Machine Learning Visualization with Spark
 
Real time machine learning visualization with spark -- Hadoop Summit 2016
Real time machine learning visualization with spark -- Hadoop Summit 2016Real time machine learning visualization with spark -- Hadoop Summit 2016
Real time machine learning visualization with spark -- Hadoop Summit 2016
 
AWS Study Group - Chapter 07 - Integrating Application Services [Solution Arc...
AWS Study Group - Chapter 07 - Integrating Application Services [Solution Arc...AWS Study Group - Chapter 07 - Integrating Application Services [Solution Arc...
AWS Study Group - Chapter 07 - Integrating Application Services [Solution Arc...
 
Mihalache catalin eip with spring integration
Mihalache catalin   eip with spring integrationMihalache catalin   eip with spring integration
Mihalache catalin eip with spring integration
 
Event-driven architecture with Java technology stack
Event-driven architecture with Java technology stackEvent-driven architecture with Java technology stack
Event-driven architecture with Java technology stack
 
Sprintintegration ajip
Sprintintegration ajipSprintintegration ajip
Sprintintegration ajip
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Ruby Microservices with RabbitMQ
Ruby Microservices with RabbitMQRuby Microservices with RabbitMQ
Ruby Microservices with RabbitMQ
 
Kafka tutorial
Kafka tutorialKafka tutorial
Kafka tutorial
 
Slides cao
Slides caoSlides cao
Slides cao
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
apachekafka-160907180205.pdf
apachekafka-160907180205.pdfapachekafka-160907180205.pdf
apachekafka-160907180205.pdf
 
quickguide-einnovator-11-spring-integration
quickguide-einnovator-11-spring-integrationquickguide-einnovator-11-spring-integration
quickguide-einnovator-11-spring-integration
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Messaging with Spring Integration
Messaging with Spring IntegrationMessaging with Spring Integration
Messaging with Spring Integration
 
Building an Event Bus at Scale
Building an Event Bus at ScaleBuilding an Event Bus at Scale
Building an Event Bus at Scale
 
ResourceSync: Web-based Resource Synchronization
ResourceSync: Web-based Resource SynchronizationResourceSync: Web-based Resource Synchronization
ResourceSync: Web-based Resource Synchronization
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
Workforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdfWorkforce Efficiency with Employee Time Tracking Software.pdf
Workforce Efficiency with Employee Time Tracking Software.pdf
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purityAPVP,apvp apvp High quality supplier safe spot transport, 98% purity
APVP,apvp apvp High quality supplier safe spot transport, 98% purity
 
CompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdfCompTIA Security+ (Study Notes) for cs.pdf
CompTIA Security+ (Study Notes) for cs.pdf
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 
IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024IT Software Development Resume, Vaibhav jha 2024
IT Software Development Resume, Vaibhav jha 2024
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 

Introduction to Kafka with Spring Integration

  • 1. Introduction to Kafka with Spring Integration
  • 2. Introduction to Kafka with Spring Integration • Kafka (Mihail Yordanov) • Spring integration (Borislav Markov) • Students Example (Mihail & Borislav) • Conclusion
  • 3. Motivation • Real time data being continuously generated • Producers and consumers relationships • Streaming systems • Messaging systems
  • 4. Apache Kafka • Developed by LinkedIn • “We built Apache Kafka at LinkedIn with a specific purpose in mind: to serve as a central repository of data streams.” - Jay Kreps • Kafka improvements – Transporting data between systems – Richer analytical processing • “A publish-subscribe messaging system rethought as a distributed commit log”
  • 5. Kafka Vocabulary • Brokers • Producers • Consumers • “A publish-subscribe messaging system rethought as a distributed commit log”
  • 6. Kafka Vocabulary • Topics • Partitions • “A publish-subscribe messaging system rethought as a distributed commit log”
  • 10. Consumer groups • Definition - “A publish-subscribe messaging system rethought as a distributed commit log” • Publish - Subscribe • Queueing
  • 11. Spring Integration • Spring Integration enables lightweight messaging • Supports integration with external systems via declarative adapters • Primary goal is to provide a simple model for building enterprise integration solutions • Separation of concerns • Maintainable, testable code
  • 12. Features • Implementation of most of the Enterprise Integration Patterns • Endpoint • Channel (Point-to-point and Publish/Subscribe) • Aggregator • Filter • Transformer • Control Bus • … • Integration with External Systems • ReST/HTTP • ...
  • 13. The theory... The patterns can be found at http://www.enterpriseintegrationpatterns.com/patterns/messag ing/index.html
  • 14. Message • Messages are objects that carry information between two applications • They are constructed by the producer and they are consumed/deconstructed at the consumer/subscriber • Message consists of: – payload – header public interface Message<T> { T getPayload(); MessageHeaders getHeaders(); }
  • 15. Message endpoints Common endpoints: • Service Activator - invokes a method on a bean • Message Bridge - couples different messaging modes/adapters. Example: (P2P with Publish/Subscribe) • Message Enricher - enrich the incoming message with additional information. – Header Enricher - add header attributes – Payload Enricher - enrich payload
  • 16. Message endpoints (continued) • Gateway - Used when we don’t have knowledge for the messaging system. – Synchronous Gateway - void or returns T – Asynchronous Gateway - returns Future<T> • Delayer - introduce delay between sender and receiver • Consumers – Polling Consumers - poll messages in a timely fashion – Polling Using Triggers - poll messages with PeriodicTrigger and with CronTrigger – Event-Driven Consumers - they wait for someone to deliver the message (framework’s responsibility)
  • 17. Message endpoints (continued) • Channel Adapter - endpoint that connects a Message Channel to some other system or transport. –inbound –outbound
  • 18. Message Channels • interface MessageChannel – boolean send(Message<?> message); – boolean send(Message<?> message, long timeout); • Point-to-Point Mode -> PollableChannel – Message<?> receive(); – Message<?> receive(long timeout); • Publish/Subscribe Mode -> SubscribableChannel – boolean subscribe(MessageHandler handler); – boolean unsubscribe(MessageHandler handler);
  • 19. Message Channels(continued) •Queue Channel - has capacity •Priority Channel - queue channel with prioritization •PublishSubscribe Channel •DirectChannel - mixed type P2P and Pub/Sub
  • 21. Flow components • Filters – Custom filters are tied to the framework, can be bean method returning boolean – Framework MessageSelector - use of method boolean accept(Message m) – Using annotation - @Filter • Routers – PayloadTypeRouter – HeaderValueRouter – Custom Routers - any bean method can be router, the result will be the channel name. – Recipient List Router - the message goes to all statically defined channels
  • 22. Flow components (continued...) • Splitters - splits a message into pieces – Custom splitters - any bean method; – Framework AbstractMessageSplitter - use of method Object splitMessage(Message m); – Using annotation - @Splitter ; • Aggregator – assemble multiple messages to create a single parent message – Complex task - all messages of a set have to arrive before aggregators can start work – CorrelationStrategy - defines the key for grouping of the messages, the default grouping is based on CORRELATION_ID – ReleaseStrategy - dictates at which point the group of messages should be sent or released for aggregation. Default is SequenceSizeReleazeStrategy – Message Store - aggregators hold messages until all of them arrived. Options are: • in-memory • external database • Resequencer - fix order of the messages(work on SEQUENCE_NUMBER)
  • 23. Transformers • Built-in transformers – String Transformers - invokes toString() method of the payload – Map Transformers - transformes POJO to a name-value pair of Map – Serializing and Deserializing Transformers - converts payload to byte array – JSON Transformers - object-to-json converts POJO to readable JSON format; json-to-object transformer needs additional property “type” – XML Transformers - requires Spring OXM (Object-to-XML); org.springframework.oxm.Marshaller/Unmarshaller
  • 24. Transformers(continued...) • Built-in transformers – XPath Transformers - decodes XML using XPath expressions, ex.: xpath- expression=”/mytag/@prop” • Custom Transformers - can be any spring bean method • Using @Transformer
  • 25. Students Example • Example application will demo usage of Kafka and Spring Integration • App is built with maven • Ideal candidate for Microservice • Idea: takes students from outside and calculates their average score
  • 27. Project Structure • Package “api” – POJO models • Package “config” – beans with factory methods • Package “service” – the business logic • Folder “resources” – application.properties
  • 31.
  • 32. Running the app and giving some inputs
  • 34. Conclusion Why Kafka and Spring ? • Easy for microservices • Clean and testable code • Widely adopted technologies • Easy to be dockerized