197 lines
6.8 KiB
HTML
197 lines
6.8 KiB
HTML
---
|
|
# The name of your project
|
|
title: Spring Cloud Stream
|
|
|
|
badges:
|
|
|
|
# Specify your project's twitter handle, if any. Delete if none.
|
|
twitter: SpringCloudOSS
|
|
|
|
# Customize your project's badges. Delete any entries that do not apply.
|
|
custom:
|
|
- name: Source (GitHub)
|
|
url: https://github.com/spring-cloud/spring-cloud-stream
|
|
icon: github
|
|
|
|
- name: Issues (Waffle)
|
|
url: https://waffle.io/spring-cloud/spring-cloud-stream
|
|
icon: tracking
|
|
|
|
- name: CI (Jenkins)
|
|
url: https://jenkins.spring.io/view/SpringCloudStream/view/CI/
|
|
icon: ci
|
|
|
|
- name: StackOverflow
|
|
url: http://stackoverflow.com/questions/tagged/spring-cloud-stream
|
|
icon: stackoverflow
|
|
|
|
---
|
|
<!DOCTYPE HTML>
|
|
<html lang="en-US">
|
|
|
|
<!-- Specify the parent of this project (or delete if none) to influence the rendering of the breadcrumb -->
|
|
{% capture parent_link %}
|
|
[Spring Cloud]({{ site.projects_site_url }}/spring-cloud)
|
|
{% endcapture %}
|
|
|
|
|
|
{% capture billboard_description %}
|
|
|
|
Spring Cloud Stream is a framework for building message-driven microservices connected with one another with messaging middleware.
|
|
It builds on Spring Boot provides both connectivity to message brokers as well as programming model for developing
|
|
microservices. Spring Cloud Stream provides an opinionated configuration of message brokers, introducing the concepts of
|
|
persistent pub/sub semantics, consumer groups and partitions across several middleware vendors. This opinionated configuration
|
|
provides the basis to create stream processing applications and is highly customizable.
|
|
|
|
{% endcapture %}
|
|
|
|
{% capture main_content %}
|
|
|
|
<span id="quick-start"></span>
|
|
|
|
## Quick Start
|
|
|
|
<script type="text/javascript">{% include custom.js %}</script>
|
|
{% include download_widget.md %}
|
|
|
|
As long as Spring Cloud Stream and a Spring Cloud Stream Binder dependencies are on the classpath any Spring Boot application with `@EnableBinding` will bind to the external
|
|
message broker (e.g. Rabbit MQ or Apache Kafka, depending on the binder-implementation of choice).
|
|
|
|
Let's see it in action!
|
|
|
|
We show you how to create a Spring Cloud Stream application that receives messages coming from the messaging middleware of your choice (more on this later) and logs received messages to the console.
|
|
We call it `LoggingConsumer`.
|
|
While not very practical, it provides a good introduction to some of the main concepts
|
|
and abstractions, making it easier to digest the rest of this user guide.
|
|
|
|
### Create a Sample Application by Using Spring Initializr
|
|
To get started, visit the [Spring Initializr](https://start.spring.io). From there, you can generate sample application. To do so:
|
|
|
|
. In the *Dependencies* section, start typing `stream`.
|
|
When the "`Cloud Stream`" option should appears, select it.
|
|
. Start typing either 'kafka' or 'rabbit'.
|
|
. Select "`Kafka`" or "`RabbitMQ`".
|
|
+
|
|
Basically, you choose the messaging middleware to which your application binds.
|
|
We recommend using the one you have already installed or feel more comfortable with installing and running.
|
|
Also, as you can see from the Initilaizer screen, there are a few other options you can choose.
|
|
For example, you can choose Gradle as your build tool instead of Maven (the default).
|
|
. In the *Artifact* field, type 'logging-consumer'.
|
|
+
|
|
The value of the *Artifact* field becomes the application name.
|
|
If you chose RabbitMQ for the middleware, your Spring Initializr should now be as follows:
|
|
|
|
```java
|
|
@SpringBootApplication
|
|
@EnableBinding(Source.class)
|
|
public class StreamdemoApplication {
|
|
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(StreamdemoApplication.class, args);
|
|
}
|
|
|
|
@Bean
|
|
@InboundChannelAdapter(value = Source.OUTPUT)
|
|
public MessageSource<String> timerMessageSource() {
|
|
return () -> new GenericMessage<>(new SimpleDateFormat().format(new Date()));
|
|
}
|
|
|
|
}
|
|
```
|
|
|
|
Make sure Kafka (0.10.1.x or later) is running when you run the application. You can use the `kafka-console-consumer.sh` utility provided by Kafka to monitor messages sent on the `output` topic.
|
|
|
|
## Kafka Client Compatibility
|
|
|
|
Spring Cloud Stream's Kafka binder builds upon Spring Kafka and Spring Integration Kafka libraries. Specifically, Spring Kafka is the core to this foundation, and it is based on the pure java `kafka-clients` jar.
|
|
|
|
The following is the compatibility matrix of Spring cloud Stream and its dependent projects (and broker versions):
|
|
|
|
<table>
|
|
<tr>
|
|
<th>Spring Cloud Stream Version</th>
|
|
<th>Spring for Apache Kafka Version</th>
|
|
<th>Spring Integration for Apache Kafka Version</th>
|
|
<th><code>kafka-clients</code> Version</th>
|
|
<th>Kafka Broker Version</th>
|
|
</tr>
|
|
<tr>
|
|
<td>2.0.x</td>
|
|
<td>2.1.x</td>
|
|
<td>3.0.x</td>
|
|
<td>1.0.x<sup>*</sup></td>
|
|
<td>1.0.x, 0.11.0.x<sup>*</sup></td>
|
|
</tr>
|
|
<tr>
|
|
<td>1.3.x</td>
|
|
<td>1.3.x, 1.2.x, 1.1.x</td>
|
|
<td>2.3.x, 2.2.x, 2.1.x</td>
|
|
<td>0.11.0.x<sup>**</sup>, 0.10.2.x</td>
|
|
<td>(Same as client)</td>
|
|
</tr>
|
|
<tr>
|
|
<td>1.2.x</td>
|
|
<td>1.2.x, 1.1.x</td>
|
|
<td>2.2.x, 2.1.x</td>
|
|
<td>0.10.1.x</td>
|
|
<td>(Same as client)</td>
|
|
</tr>
|
|
</table>
|
|
|
|
Depending on the selected release-combination, the dependent projects will be referenced transitively when using maven or gradle for version management.
|
|
<br/><br/>
|
|
The 2.0.x binder uses the pure java `AdminClient` to provision topics and supports native headers.
|
|
The 1.0.x client can communicate with an 0.11.x.x broker (which also supports headers).
|
|
When using with a 0.11.x.x broker, topics can be provisioned, but the number of partitions cannot be automatically adjusted up.
|
|
To increase the number of topics, you must use the kafka tools instead.
|
|
The property `spring.cloud.stream.kafka.binder.auto-add-partitions` must be `false` (default).
|
|
<br/>
|
|
To use the 0.11.x.x `kafka-clients` with 1.3.x, you must use the `spring-cloud-stream-binder-kafka11` jar (instead of `spring-cloud-stream-binder-kafka`). You must also override certain other jar versions as follows:
|
|
|
|
<table>
|
|
<tr>
|
|
<td>spring-cloud-stream-binder-kafka11</td>
|
|
<td>1.3.0.RELEASE or higher</td>
|
|
</tr>
|
|
<tr>
|
|
<td>spring-kafka</td>
|
|
<td>1.3.2.RELEASE or higher</td>
|
|
</tr>
|
|
<tr>
|
|
<td>spring-integration-kafka</td>
|
|
<td>2.3.0.RELEASE or higher</td>
|
|
</tr>
|
|
<tr>
|
|
<td>spring-integration-core</td>
|
|
<td>4.3.13.RELEASE or higher</td>
|
|
</tr>
|
|
<tr>
|
|
<td>spring-integration-jmx</td>
|
|
<td>4.3.13.RELEASE or higher</td>
|
|
</tr>
|
|
<tr>
|
|
<td>kafka_2.11</td>
|
|
<td>(same version as kafka-clients)</td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
{% endcapture %}
|
|
|
|
{% capture related_resources %}
|
|
|
|
### Sample Projects
|
|
|
|
* [Spring Cloud Stream Samples](https://github.com/spring-cloud/spring-cloud-stream-samples)
|
|
|
|
### Related Projects
|
|
|
|
* [Spring Cloud Stream Applications](http://cloud.spring.io/spring-cloud-stream-app-starters/)
|
|
* [Spring Cloud Data Flow](http://cloud.spring.io/spring-cloud-dataflow/)
|
|
|
|
{% endcapture %}
|
|
|
|
|
|
{% include project_page.html %}
|
|
</html>
|