DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Merge GraphQL Schemas Using Apollo Server and Koa
  • Is Podman a Drop-in Replacement for Docker?
  • Exploratory Testing Tutorial: A Comprehensive Guide With Examples and Best Practices

Trending

  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Merge GraphQL Schemas Using Apollo Server and Koa
  • Is Podman a Drop-in Replacement for Docker?
  • Exploratory Testing Tutorial: A Comprehensive Guide With Examples and Best Practices
  1. DZone
  2. Coding
  3. Frameworks
  4. Stream Processing in Spring XD 1.1

Stream Processing in Spring XD 1.1

Pieter Humphrey user avatar by
Pieter Humphrey
CORE ·
Mar. 06, 15 · Interview
Like (0)
Save
Tweet
Share
4.63K Views

Join the DZone community and get the full member experience.

Join For Free
Written by Josh Long on the Spring Blog

This tip is drawn heavily from this Wiki-page on Spring XD’s streaming support by various Spring XD team-members, and particularly the amazing Ilayaperumal Gopinathan

Spring XD 1.1 is here and is packed with lots of new features. One theme for this release is rich stream processing support. Spring XD 1.1 provides integration with Project Reactor Streams,RxJava Observables, and Spark’s streaming.

Let’s look specifically at using Reactor, though the concepts are similar across all of the supported streaming APIs.

Messages that are delivered on the Message Bus are accessed from the input Stream. The return value is the output Stream that is the result of applying various operations to the input stream. The content of the output Stream is sent to the message bus for consumption by other processors or sinks. To implement a Stream-based processor module you need to implement the interface org.springframework.xd.reactor.Processor:

import org.springframework.xd.reactor.Processor;
import org.springframework.xd.tuple.Tuple;
import reactor.rx.Stream;

import static com.acme.Math.avg;
import static org.springframework.xd.tuple.TupleBuilder.tuple;

public class MovingAverage implements Processor<Tuple, Tuple> {

  @Override
  public Stream<Tuple> process(Stream<Tuple> inputStream) {
    return inputStream.map(tuple -> tuple.getDouble("measurement"))
      .buffer(5)
      .map(data -> tuple().of("average", avg(data)));
  }
}

Writing a test for this is as simple as setting up a Spring Integration flow that takes input on a request channel and routes it to this processor via aorg.springframework.xd.reactor.SynchronousDispatcherMessageHandler component which itself writes its output to an output channel. From there, you can package and registerthe custom processor in the Spring XD admin server.


Stream processing Spring Framework

Published at DZone with permission of Pieter Humphrey, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Mastering Time Series Analysis: Techniques, Models, and Strategies
  • Merge GraphQL Schemas Using Apollo Server and Koa
  • Is Podman a Drop-in Replacement for Docker?
  • Exploratory Testing Tutorial: A Comprehensive Guide With Examples and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: