@SpringBootApplication
@EnableBinding(Sink.class)
public class VoteRecordingSinkApplication {
public static void main(String[] args) {
SpringApplication.run(VoteRecordingSinkApplication.class, args);
}
@StreamListener(Sink.INPUT)
public void processVote(Vote vote) {
votingService.recordVote(vote);
}
}
@EnableBinding(Processor.class)
@EnableAutoConfiguration
public static class UppercaseTransformer {
@StreamListener
@Output(Processor.OUTPUT)
public Flux<String> receive(@Input(Processor.INPUT) Flux<String> input) {
return input.map(s -> s.toUpperCase());
}
}
with a RabbitMQ output binder
public interface MyChannels {
@Output("some-output")
MessageChannel output();
}
spring.jms.pub-sub-domain=true
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
When using JMS:
@RestController
@SpringBootApplication
@EnableBinding(MyChannels.class)
public class SpringCloudStreamDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCloudStreamDemoApplication.class, args);
}
@Autowired
private MyChannels myChannels;
@GetMapping(params = "message")
public void sendMessage(@RequestParam("message") String message) {
this.myChannels.output().send(MessageBuilder.withPayload(message).build());
}
@StreamListener("some-output")
public void receiveMessage(String message) {
System.out.println(message);
}
}
with a RabbitMQ output binder
of pub-sub style communication
splitting up workload
Genius. Grandpa. Asshole.
Genius. Grandpa. Asshole.
Rick Microservice
RabbitMQ Binder
RabbitMQ
Existence is pain.
Existence is pain.
Meeseeks microservice
RabbitMQ Binder
RabbitMQ
One in five hundred chance to win.
McDonalds microservice
RabbitMQ Binder
RabbitMQ
The perfect sidekick.
Morty microservice
RabbitMQ Binder
RabbitMQ
RabbitMQ
Scale up/down
The Microverse
public interface PolledConsumer {
@Input
PollableMessageSource destIn();
@Output
MessageChannel destOut();
}
@SpringBootApplication
@EnableBinding(KStreamProcessor.class)
public class WordCountProcessorApplication {
@StreamListener("input")
@SendTo("output")
public KStream<?, WordCount> process(KStream<?, String> input) {
return input
.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
.groupBy((key, value) -> value)
.windowedBy(TimeWindows.of(5000))
.count(Materialized.as("WordCounts-multi"))
.toStream()
.map((key, value) -> new KeyValue<>(null, new WordCount(key.key(), value, new Date(key.window().start()), new Date(key.window().end()))));
}
public static void main(String[] args) {
SpringApplication.run(WordCountProcessorApplication.class, args);
}