Dave Syer, 2016
Twitter: @david_syer
Email: dsyer@pivotal.io
Life after REST
Patterns:
Conclusion: There is a range of applications and problems to which messaging is an effective solution.
Simple things should be easy, and complex things should be possible.
Alan Kay
@EnableBinding(Source.class)
@SpringBootApplication
public class Application {
@Autowired
Source source;
@RequestMapping(value="/", method=POST)
public String send() {
source.output()
.send(MessageBuilder.withPayload("Hello World").build);
return "OK";
}
}
Answer: it's an interface...
public interface Source {
String OUTPUT = "output";
@Output(Source.OUTPUT)
MessageChannel output();
}
+--------+ +---------------------------+
| Source |---->| "output" |
+--------+ +---------------------------+
+--------+ +---------------------------+ +---------+
| Source |---->| "output" |---->| Sink |
+--------+ +---------------------------+ +---------+
@EnableBinding(Source.class)
...
@EnableBinding(Sink.class)
...
@EnableBinding(Processor.class)
...
or even
@EnableBinding(MyCoffeeShop.class)
You can use the MessageChannel
interfaces (e.g. inject a SubscribableChannel
and subscribe to it).
@EnableBinding(Processor.class)
public class TransformProcessor {
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object transform(String message) {
return message.toUpper();
}
}
Or you can use a @StreamListener
(more like @RequestMapping
):
@EnableBinding(Processor.class)
public class TransformProcessor {
...
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public VoteResult handle(Vote vote) {
return record(vote);
}
}
(With @StreamListener
you also get support for Reactor and RxJava.)
@SpringBootApplication
public class Task {
@Bean
public ApplicationRunner(Source source) {
return app -> { System.out.println("Hello World"); };
}
...
}
@EnableTask
@SpringBootApplication
public class Task {
@Bean
public ApplicationRunner(Source source) {
return app -> { System.out.println("Hello World"); };
}
...
}
A programming and operating model for streams and tasks on a structured platform.
Components:
It's an SPI. Examples:
+---------------------------------+
| Client | (shell or browser)
+---------------------------------+
|^
Platform v| (cf, k8s, mesos, etc.)
+---------------------------------+
| +------+ +------+ |
| |Server| | DB | |
| +------+ +------+ |
| +----+----+----+----+----+----+ |
| | | |Apps| | | | | (streams and tasks)
| +-----------------------------+ |
| | Transport | | (rabbit, kafka, etc.)
+---------------------------------+
Streams have a DSL, e.g. http | transform | hdfs
, but fundamentally
they are just apps sending each other messages. Each node in the
pipeline is a Spring Boot app using Spring Cloud Stream.
Tasks are short- (or finite-) lived apps. Data Flow orchestrates them and uses Spring Cloud Task to record their exit status.
/
#