/
Developing  a Message Driven Architecture with Developing  a Message Driven Architecture with

Developing a Message Driven Architecture with - PowerPoint Presentation

projoutr
projoutr . @projoutr
Follow
342 views
Uploaded On 2020-08-27

Developing a Message Driven Architecture with - PPT Presentation

Spring an Overview Silicon India Java Conference Hyderabad October 15 2011 Introduction Karthik Banda Technology Specialist with Deloitte Consulting India practicing Software Engineering for more ID: 803994

message spring driven integration spring message integration driven jms task messaging eda application method architecture meda messages taskexecutor events

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "Developing a Message Driven Architectur..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Developing a Message Driven Architecture with Spring – an OverviewSilicon India Java Conference, Hyderabad

October 15, 2011

Slide2

Introduction – Karthik BandaTechnology Specialist with Deloitte Consulting India, practicing Software Engineering for more than a decade now Defined Technical architecture for multiple strategic projects for clients across domains, but predominantly in Financial Services Industry

Deep experience in creating application development frameworks and solution sets using

Java

Leads

the

competency development of Java

Community of Practice at

Deloitte Consulting India

T

rainer and a speaker - conducted

multiple tech-talks predominantly around Architecture, Design and Software Engineering best practices.

Member of Scrum Alliance and a certified Scrum Master

Slide3

AgendaArchitectural Context for IntegrationArchitectural Patterns in DiscussionEvent Driven Architecture (EDA)Spring as EDA enabler

Message Driven Architecture Java Message Service (JMS)

Message Exchange Patterns

Message Driven Beans in EJB 3 and Message Driven POJO’s

Realizing Message driven designs with Spring

Spring Task Execution and Scheduling

Spring Integration

Q&A

Slide4

Common Architectural contexts and respective ChoicesIntegration and communication styles– Online / Real Time Integration – SOA Enablers – ESB / MOM / JMS / XML/RPC/JCA and Web Services

Offline Integration – Scheduled Batch processes, Polling

Synchronous Communication – RMI / RPC/JCA /Web Services

Asynchronous Communication – Service Activation / JMS / Asynchronous web-service calls

Message

Channeling, Routing, Aggregation – ESB or could be Spring Integration

Slide5

Event Driven Architecture (EDA) – in a NutshellOne of the key design principle is - Low Coupling and High CohesionEDA gives the flexibility to define clearly the boundaries and responsibilities of classes in collaboration but keeping their level of dependency to the minimum

Example : “What Should I do on successful booking of a ticket”

EDA is all about transmitting events between different components in a system and clearly defining a way to handle them

An “Event” generally represents a change in the state of a system

Example : “ Booked a Ticket

Successfully”

EDA avoids any coupling between subsystems as it takes away the normal command and control scheme i.e. one class calling a method of another “known” class and waiting for it to respond.

Slide6

EDA – CharacteristicsEvents are broadcasted whenever they occur and they are fine grainedEvents typically are handled Asynchronously and the Caller is not aware of CalleeFundamental principle of “

Services” to be stateless can be easily achieved No blocking times – Events no longer takes place one at a time, and the order of events is no longer important.

Slide7

EDA – Spring - Sending Application Events1. Publisher injected by the container – Setter Injection in this case2. Use the publisher to send events at runtime.

Slide8

EDA – Spring - Handling Application Events1. Implement the ApplicationListener interface with a parameterized type.2. Define the bean, and it will be invoked at runtime when that type of Event occurs.

Slide9

Message Driven Architecture (MeDA)- JMS - in a NutshellOne of the common architectural choice to integrate disparate systems in a distributed environment is Messaging

Uses a Middleware to facilitate messaging i.e. to queue sent messages and handle them – Message Oriented Middleware (MOM)Message Producers and Consumers are not aware of each other

JMS is a MOM standard and is a vendor neutral specification for messaging

Features of JMS include

Point to Point Messaging (Queues) (1sender-1receiver)

Publish and Subscribe (Topics) (1publisher – N subscribers)

Reliable Message Delivery

Message Persistence

Transactional

Structured Messaging

Slide10

MeDA – Messaging Domains / ModelsPoint to Point Messaging Domain – Messages are sent to queues and are delivered only once and that too to a single consumer. Queues retain messages until consumed or expired

Publish and Subscribe

Messaging Domain

– Messages are sent to

topics and

are delivered

to all the subscribers. Ideal for publishing business events and it is one flavor of implementing EDA.

Slide11

MeDA – Implementation choice – Message Driven BeansCharacteristics of Message Driven BeansMessage Driven beans are state less server side Java objects for handling JMS Messages and processing them asynchronouslyDeveloped as part of EJB 2.0 specificationHighly scalable server side components as they are easily managed and/or distributed

Disadvantages of Message Driven BeansMandates the need for an EJB container / JEE application Server

Heavy life cycle as part of EJB specification (Nothing changed in EJB 3

)

Each MDB listens to a single destination

Cannot be part of domain model as they are otherwise are not reusable

Normal leverage is only to the extent of “Services Activation”

Slide12

MeDA – Implementation choice – Message Driven POJOCharacteristics of Message Driven POJOThese can be part of domain model as they are normal java classes with no additional baggageThese classes are JMS unaware

Developer need not worry about JMSEasily testableDisadvantages of Message Driven POJO’s

Developers think in terms of Command – Control instead of Messaging and Asynchronous communication as these POJO’s are not treated separately as “Special Objects”

Needs plumbing code to leverage JMS resources. Needs more attention to “Separation of Concerns”.

No standard interfaces are implemented by limiting their power of interface injection

Slide13

MeDA – Spring – Sending JMS Messages1. Abstract JMS Administered objects into a JmsTemplate 2. Inject an instance of Spring's JmsTemplate into the sending class3. Provide the JMS ConnectionFactory in the JmsTemplate bean definition

Slide14

MeDA – Spring – Listening for JMS Messages1. Define a “listener-container” within the context and specify the destination that needs to be looked at for receiving messages2. Point to any POJO and specify a listening method to implicitly create a

MessageListenerAdapter

Slide15

MeDA – Spring – Advanced Message Queuing Protocol AMQP is an open standard application layer protocol for message-oriented middlewareOne level ahead of JMS – unlike JMS, AMQP is a wired protocol

Dictates the format of messages during data transfer across networks

Slide16

MeDA – Spring – Sending/Receiving AMQP Messages1. Use AmqpTemplate which accepts Exchange and Routing Key

2. Point to any POJO and specify a listening method to implicitly create a MessageListenerAdapter for AMQP messages.

Slide17

Polling – An architectural pattern (Better avoid)Better to use events/messaging and only poll when you have to Lifecycle interface – start(), stop() and isRunning() - This supports any basic back ground task and a common usage is polling

SmartLifecycle does those three plus autostartup, phases and adds a callback on stop – gives a handle on the running thread to the application to end gracefully.

Slide18

Task Execution using ExecutorsThe Spring Framework provides abstractions for asynchronous execution of tasks with the TaskExecutor interfaceThe

TaskExecutor interface has a single method execute(Runnable task)The

TaskExecutor

gives Spring components an abstraction for thread pooling where needed

Multiple pre-built implementations of

TaskExecutor

are included in Spring 3 which covers most of the patterns of task execution

Slide19

Task Execution – by configuration

Important thing to note is that the execute method here adds a Runnable

thread to the queue and the

TaskExecutor

uses its internal rules to decide when the task gets executed, depending on the Implementation class we choose

to inject.

We can easily change

a particular behavior or pattern of task execution

by changing the Implementation strategy.

Slide20

Task Execution – @Async Annotation@Async – adds an implicit

TaskExecutor Support to a methodSpring internally uses a Dynamic Proxy for @

Async

annotated method so that the method is actually executed by the implementation class of

TaskExecutor

Slide21

Task Scheduling The Spring Framework provides abstractions for asynchronous scheduling of tasks with the TaskScheduler interface supported by Trigger and TriggerContext interfaces

TaskScheduler supports recurring and cancelable tasks and they can be easily controlled

Slide22

Task Scheduling – by configurationThe Example below shows a POJO which can be turned into a business service that can be executed as a Cron Job with basic configuration.

This Example uses Cron

Expression “3/10 ****?” which is nothing but a 3 seconds offset and runs every 10

secs

in a minute.

Other Possible Triggers are “fixed-delay” and “fixed-rate” which are configured in milliseconds.

Slide23

Task Scheduling – @Scheduled AnnotationThe @Scheduled annotation can be added to a method along with trigger metadata

Start at Every Five seconds after completion of each run

Start at Every Five seconds after starting each run

Cron

Job that executes on week days

Slide24

Spring Integration – A bird-eye viewEnterprise Application Integration (EAI) is an application of technology defined as the integration of data and services between applications.

Spring Integration is an API from the creators of the Spring Framework that's geared towards Enterprise Application Integration (EAI).

Spring Integration offers improvement on every integration solution that exists in Java world.

Can be a powerful alternative to an ESB

Spring Integration addresses this concern – “As the number of integration points

increases

the applications will have to maintain and manage many point to point channels of communication and the convergence of these channels

at various end points create

“spaghetti architecture

”.

Key Parts of Spring Integration :

Message–Pay Load–Header–Channel–Gateway

Slide25

Spring Integration – A Simple ExampleThis example uses Spring Integration to process a book order and appropriately route the message depending on if it's a pickup from the store or if it should be delivered by post.

Slide26

Spring Integration – A Simple Example – @Gateway

Slide27

Spring Integration – A Simple Example – @Router

Slide28

Spring Integration – A Simple Example – Bridge

Slide29

Spring Integration – A Simple Example – @Transformer

Slide30

Spring Integration – Outbound Channel Adapter

Slide31

Annotations – Dynamic Language Support – Spring EL

Slide32

Channel Adapters and Message Gateways Supported• JMS• AMQP• TCP• UDP• File/FTP/SFTP

• RMI• RSS• HTTP (REST) • WS (SOAP/POX)• Mail (POP3/IMAP/SMTP)

• JDBC

• XMPP

• Twitter

• Spring Events

Slide33

Questions and Answers – bkarthik@deloitte.com

Slide34

Copyright © 2011 Deloitte Development LLC. All rights reserved.