permission is prohibited. Automating Operations with Spring Batch and Spring Integration Dave Syer and Mark Fisher – SpringSource, a division of VMware
permission is prohibited. 2 Spring Batch Application Batch Core Batch Infrastructure Re-usable low level stuff: flat files, XML files, database keys Quality of service, auditability, management information Business Logic
permission is prohibited. 6 ItemStream ItemStream open(executionContext) save(executionContext) close() Called before commit Step JobRepository ExitStatus execute() repeat, retry, etc. update(executionContext)
permission is prohibited. 7 Job Configuration and Execution Job JobInstance JobExecution * * The EndOfDay Job The EndOfDay Job for 2007/05/05 The first attempt at EndOfDay Job for 2007/05/05 JobParameters schedule.date = 2007/05/05
permission is prohibited. 10 Spring Batch Roadmap • 2.1 released 2010Q1 • Spring 3.0; configuration convenience • In use at 100+ projects with scores in production • 3.0 planned 2011Q1 • Distributed JobRepository
permission is prohibited. 12 What is Spring Integration? • At the core, an embedded Message Bus – Runs within any Spring ApplicationContext – All components are Spring-managed objects • Also, an Application Integration Framework – Connects to other systems via adapters • Unidirectional Channel Adapters • Bidirectional Messaging Gateways
permission is prohibited. 16 Message Channel • Decouples Producers from Consumers • Provides extension point for interceptors • May be Point-to-Point • Or Publish/Subscribe
permission is prohibited. 18 JMS-backed Message Channels • Drop-in replacement for <channel/> elements • Enables full power of underlying JMS provider – Persistence, transactions, etc. • Point-to-Point delegates to a JMS Queue • Publish/Subscribe delegates to a Topic <jms:channel id="p2p" queue-name="someQueueName"/> <jms:publish-subscribe-channel id="pubsub" topic="someTopicRef"/>
permission is prohibited. 19 Message Endpoint • Producers send Messages to a Message Channel • Depending on their type, Message Channels may have Polling Consumers • Or Event-Driven Consumers
permission is prohibited. 20 Service Activator • Similar in concept to Spring's JMS support – delegate to any Spring-managed object – the framework handles message reception and method invocation • Clean separation of Code and Configuration <service-activator input-channel="requests" ref="loanBroker" method="processRequest" output-channel="quotes"/>
permission is prohibited. 21 Other Message Endpoints • Transformer – Convert payload or modify headers • Filter – Discard messages based on boolean evaluation • Router – Determine next channel based on content • Splitter – Generate multiple messages from one • Aggregator – Assemble a single message from multiple
permission is prohibited. 22 Expression Language Support • Alternative option for ref/method in endpoints <filter input-channel="customers" expression="payload.vip" output-channel="vips" discard-channel="nonVips"/> • Mapping between Messages and Methods public void createAccount( @Payload("firstName") String firstName, @Payload("lastName") String lastName, @Header("account.id") String accountId) {...}
permission is prohibited. 25 Combining Batch and Integration • Adding messaging to a batch process enables automation of operations – Message triggers Jobs – Job completion or failure triggers Message • Messaging can also be embedded within a Job – Reading or writing items via channels • The line is not always clear, but there are guidelines – Think about granularity – Apply common patterns
permission is prohibited. 27 Pattern: Message Driven Job Configuration • Job configuration sometimes needs to be updated • Example: change the timeout for a remote process JobRegistry Job configuration
permission is prohibited. 30 Pattern: Monitor Channel • Informational messages about status of system • Can be adapter to multiple outbound endpoints – e.g. E-mail, SMS, XMPP, etc. XMPP
permission is prohibited. 31 Pattern: Channel Reuse • More than one source for the same event • Efficient because of modularity • Example: File Polling and inbound HTTP Transformation might be necessary