diff --git a/spring-cloud.html b/spring-cloud.html index 734ce481..f71c8cfe 100644 --- a/spring-cloud.html +++ b/spring-cloud.html @@ -570,7 +570,17 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
Version: $1.1.0.BUILD-SNAPSHOT
+Version: Brixton.BUILD-SNAPSHOT
serviceUrl) with default duration 30 seconds. A
service is not available for discovery by clients until the instance,
the server and the client all have the same metadata in their local
-cache (so it could take 3 hearbeats). You can change the period using
+cache (so it could take 3 heartbeats). You can change the period using
eureka.instance.leaseRenewalIntervalInSeconds and this will speed up
the process of getting clients connected to other services. In
production it’s probably better to stick with the default because
@@ -3724,7 +3733,7 @@ for details on the properties available.
You can then point the Hystrix Dashboard to the Turbine Stream Server instead of individual Hystrix streams. If Turbine Stream is running on port 8989 on myhost, then put http://myhost:8989 in the stream input field in the Hystrix Dashboard. Circuits will be prefixed by their respective serviceId, followed by a dot, then the circuit name.
Spring Cloud provides a spring-cloud-starter-turbine-stream that has all the dependencies you need to get a Turbine Stream server running - just add the Sream binder of your choice, e.g. spring-cloud-starter-stream-rabbit. You need Java 8 to run the app because it is Netty-based.
Spring Cloud provides a spring-cloud-starter-turbine-stream that has all the dependencies you need to get a Turbine Stream server running - just add the Stream binder of your choice, e.g. spring-cloud-starter-stream-rabbit. You need Java 8 to run the app because it is Netty-based.
These simple url-routes doesn’t get executed as HystrixCommand nor can you loadbalance multiple url with Ribbon. -To achieve this specify a service-route and configure a Ribbon client for the +
These simple url-routes don’t get executed as a HystrixCommand nor can you loadbalance multiple URLs with Ribbon.
+To achieve this, specify a service-route and configure a Ribbon client for the
serviceId (this currently requires disabling Eureka support in Ribbon:
see above for more information), e.g.
You can provide convention between serviceId and routes using -regexmapper. It uses regular expression named group to extract +regexmapper. It uses regular expression named groups to extract variables from serviceId and inject them into a route pattern.
This means that a serviceId "myusers-v1" will be mapped to route "/v1/myusers/**". Any regular expression is accepted but all named -group must be present in both servicePattern and routePattern. If -servicePattern do not match a serviceId, the default behavior is -used. In exemple above, a serviceId "myusers" will be mapped to route -"/myusers/**" (no version detected) These feature is disable by -default and is only applied to discovered services.
+groups must be present in both servicePattern and routePattern. If +servicePattern does not match a serviceId, the default behavior is +used. In the example above, a serviceId "myusers" will be mapped to route +"/myusers/**" (no version detected) This feature is disable by +default and only applies to discovered services.To add a prefix to all mappings, set zuul.prefix to a value, such as
@@ -4577,7 +4586,7 @@ the service-specific prefix from individual routes, e.g.
In this example requests to "/myusers/101" will be forwarded to "/myusers/101" on the "users" service.
+In this example, requests to "/myusers/101" will be forwarded to "/myusers/101" on the "users" service.
The zuul.routes entries actually bind to an object of type ZuulProperties. If you
@@ -4594,13 +4603,13 @@ picks up a header "X-Forwarded-Prefix" ("/myusers" in the examples
above).
An application with the @EnableZuulProxy could act as a standalone
+
An application with @EnableZuulProxy could act as a standalone
server if you set a default route ("/"), for example zuul.route.home:
/ would route all traffic (i.e. "/**") to the "home" service.
If more fine-grained ignoring is needed, you can specify specific patterns to ignore. -These patterns are being evaluated at the start of the route location process, which +These patterns are evaluated at the start of the route location process, which means prefixes should be included in the pattern to warrant a match. Ignored patterns span all services and supersede any other route specification.
The sensitive headers can be configured as a comma-separate list per +
The sensitive headers can be configured as a comma-separated list per route, e.g.
Sensitive headers can also be set globally setting zuul.sensitiveHeaders. If sensitiveHeaders is set on a route, this will override the global sensitiveHeaders setting.
Sensitive headers can also be set globally by setting zuul.sensitiveHeaders. If sensitiveHeaders is set on a route, this will override the global sensitiveHeaders setting.
| -The ignored pattterns aren’t completely ignored, they just +The ignored patterns aren’t completely ignored, they just aren’t handled by the proxy (so they are also effectively forwarded locally). | @@ -5539,8 +5548,8 @@ When doing this, different instances of an application are placed in a competing
|
+ Note
+ |
+
+
+
+Turning on explicit binder configuration will disable the default binder configuration process altogether.
+If you do this, all binders in use must be included in the configuration.
+Frameworks that intend to use Spring Cloud Stream transparently may create binder configurations that can be referenced by name, but will not affect the default binder configuration.
+In order to do so, a binder configuration may have its |
+
For example, this is the typical configuration for a processor application which connects to two RabbitMQ broker instances:
+spring:
+ cloud:
+ stream:
+ bindings:
+ input:
+ destination: foo
+ binder: rabbit1
+ output:
+ destination: bar
+ binder: rabbit2
+ binders:
+ rabbit1:
+ type: rabbit
+ environment:
+ spring:
+ rabbitmq:
+ host: <host1>
+ rabbit2:
+ type: rabbit
+ environment:
+ spring:
+ rabbitmq:
+ host: <host2>
+The following properties are available when creating custom binder configurations.
+They must be prefixed with spring.cloud.stream.binders.<configurationName>.
The binder type.
+It typically references one of the binders found on the classpath, in particular a key in a META-INF/spring.binders file.
By default, it has the same value as the configuration name.
+Whether the configuration will inherit the environment of the application itself.
+Default true.
Root for a set of properties that can be used to customize the environment of the binder. +When this is configured, the context in which the binder is being created is not a child of the application context. +This allows for complete separation between the binder components and the application components.
+Default empty.
Whether the binder configuration is a candidate for being considered a default binder, or can be used only when explicitly referenced. +This allows adding binder configurations without interfering with the default processing.
+Default true.
This section details the binder implementation strategies for Kafka and Rabbit MQ, in what concerns mapping the Spring Cloud Stream concepts onto the middleware concepts.
+spring.cloud.stream.bindings.<channelName>.destination
-
The target destination of a channel on the bound middleware (e.g., the RabbitMQ exchange or Kafka topic).
+If the channel is bound as a consumer, it could be bound to multiple destinations and the destination names can be specified as comma separated String values.
If not set, the channel name is used instead.
- group
@@ -6339,24 +6559,21 @@ Useful when inbound data is coming from outside Spring Cloud Stream applications
- maxAttempts
-
-
The number of attempts of re-processing an inbound message.
-Currently ignored by Kafka.
+The number of attempts of re-processing an inbound message.
Default: 3.
- backOffInitialInterval
-
-
The backoff initial interval on retry.
-Currently ignored by Kafka.
+The backoff initial interval on retry.
Default: 1000.
- backOffMaxInterval
-
-
The maximum backoff interval.
-Currently ignored by Kafka.
+The maximum backoff interval.
Default: 10000.
@@ -6542,6 +6759,13 @@ Only effective if group is also set.
Default: "".
The interval between connection recovery attempts, in milliseconds.
+Default: 5000.
Whether delivery failures should be requeued.
@@ -6732,9 +6956,8 @@ Mutually exclusive withoffsetUpdateTimeWindow.
Effective only if autoCreateTopics or autoAddPartitions is set.
- The global minimum number of partitions that the binder will configure on topics on which it produces/consumes data.
-It can be superseded by the partitionCount setting of the producer or by the value of
-instanceCount * concurrency settings of the producer (if either is larger).
partitionCount setting of the producer or by the value of instanceCount * concurrency settings of the producer (if either is larger).
Default: 1.
auto.topic.create.enable
If set to true, the binder will create add new partitions if required.
If set to false, the binder will rely on the partition size of the topic being already configured.
-If the partition count of the target topic is smaller than the expected value, the binder will fail to start.
-Default: false.
Default: false.
Size (in bytes) of the socket buffer to be used by the Kafka consumers.
+Default: 2097152.
false, an Acknowledgment header will be avai
Default: true.
Effective only if autoCommitOffset is set to true.
+If set to false it suppresses auto-commits for messages that result in errors, and will commit only for successful messages, allows a stream to automatically replay from the last successfully processed message, in case of persistent failures.
+If set to true, it will always auto-commit (if auto-commit is enabled).
+If not set (default), it effectively has the same value as enableDlq, auto-committing erroneous messages if they are sent to a DLQ, and not committing them otherwise.
Default: not set.
+The interval between connection recovery attempts, in milliseconds.
+Default: 5000.
Whether to reset offsets on the consumer to the value provided by startOffset.
spring.cloud.stream.kafka.bindings.<channelName&g
Spring Cloud Stream relies on implementations of the Binder SPI to perform the task of connecting channels to message brokers. -Each Binder implementation typically connects to one type of messaging system. -Out of the box, Spring Cloud Stream provides binders for Kafka, RabbitMQ, and Redis.
-By default, Spring Cloud Stream relies on Spring Boot’s auto-configuration to configure the binding process. -If a single Binder implementation is found on the classpath, Spring Cloud Stream will use it automatically. -For example, a Spring Cloud Stream project that aims to bind only to RabbitMQ can simply add the following dependency:
-<dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
-</dependency>
-When multiple binders are present on the classpath, the application must indicate which binder is to be used for each channel binding.
-Each binder configuration contains a META-INF/spring.binders, which is a simple properties file:
rabbit:\
-org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration
-Similar files exist for the other provided binder implementations (e.g., Kafka), and custom binder implementations are expected to provide them, as well.
-The key represents an identifying name for the binder implementation, whereas the value is a comma-separated list of configuration classes that each contain one and only one bean definition of type org.springframework.cloud.stream.binder.Binder.
Binder selection can either be performed globally, using the spring.cloud.stream.defaultBinder property (e.g., spring.cloud.stream.defaultBinder=rabbit) or individually, by configuring the binder on each channel binding.
-For instance, a processor application which reads from Kafka and writes to RabbitMQ can specify the following configuration:
spring.cloud.stream.bindings.input.binder=kafka -spring.cloud.stream.bindings.output.binder=rabbit-
By default, binders share the application’s Spring Boot auto-configuration, so that one instance of each binder found on the classpath will be created. -If your application should connect to more than one broker of the same type, you can specify multiple binder configurations, each with different environment settings.
-|
- Note
- |
-
-
-
-Turning on explicit binder configuration will disable the default binder configuration process altogether. -If you do this, all binders in use must be included in the configuration. - |
-
For example, this is the typical configuration for a processor application which connects to two RabbitMQ broker instances:
-spring:
- cloud:
- stream:
- bindings:
- input:
- destination: foo
- binder: rabbit1
- output:
- destination: bar
- binder: rabbit2
- binders:
- rabbit1:
- type: rabbit
- environment:
- spring:
- rabbitmq:
- host: <host1>
- rabbit2:
- type: rabbit
- environment:
- spring:
- rabbitmq:
- host: <host2>
-Spring Cloud Stream allows you to declaratively configure type conversion for inputs and outputs using the content-type property of a binding.
+Note that general type conversion may also be accomplished easily by using a transformer inside your application.
+Currently, Spring Cloud Stream natively supports the following type conversions commonly used in streams:
JSON to/from POJO
+JSON to/from org.springframework.tuple.Tuple
+Object to/from byte[] : Either the raw bytes serialized for remote transport, bytes emitted by an application, or converted to bytes using Java serialization(requires the object to be Serializable)
+String to/from byte[]
+Object to plain text (invokes the object’s toString() method)
+Where JSON represents either a byte array or String payload containing JSON. +Currently, Objects may be converted from a JSON byte array or String. +Converting to JSON always produces a String.
+content-type values are parsed as media types, e.g., application/json or text/plain;charset=UTF-8.
+MIME types are especially useful for indicating how to convert to String or byte[] content.
+Spring Cloud Stream also uses MIME type format to represent Java types, using the general type application/x-java-object with a type parameter.
+For example, application/x-java-object;type=java.util.Map or application/x-java-object;type=com.bar.Foo can be set as the content-type property of an input binding.
+In addition, Spring Cloud Stream provides custom MIME types, notably, application/x-spring-tuple to specify a Tuple.
The type conversions Spring Cloud Stream provides out of the box are summarized in the following table:
+| Source Payload | +Target Payload | +content-type header | +content-type | +Comments | +
|---|---|---|---|---|
POJO |
+JSON String |
+ignored |
+application/json |
++ |
Tuple |
+JSON String |
+ignored |
+application/json |
+JSON is tailored for Tuple |
+
POJO |
+String (toString()) |
+ignored |
+text/plain, java.lang.String |
++ |
POJO |
+byte[] (java.io serialized) |
+ignored |
+application/x-java-serialized-object |
++ |
JSON byte[] or String |
+POJO |
+application/json (or none) |
+application/x-java-object |
++ |
byte[] or String |
+Serializable |
+application/x-java-serialized-object |
+application/x-java-object |
++ |
JSON byte[] or String |
+Tuple |
+application/json (or none) |
+application/x-spring-tuple |
++ |
byte[] |
+String |
+any |
+text/plain, java.lang.String |
+will apply any Charset specified in the content-type header |
+
String |
+byte[] |
+any |
+application/octet-stream |
+will apply any Charset specified in the content-type header |
+
Conversion applies to payloads that require type conversion. +For example, if a module produces an XML string with outputType=application/json, the payload will not be converted from XML to JSON. +This is because the payload at the module’s output channel is already a String so no conversion will be applied at runtime.
+While conversion is supported for both input and output channels, it is especially recommended to be used for the conversion of outbound messages.
+For the conversion of inbound messages, especially when the target is a POJO, the @StreamListener support will perform the conversion automatically.
`@StreamListener and Message ConversionThe @StreamListener annotation provides a convenient way for converting incoming messages without the need to specify the content type of an input channel.
+During the dispatching process to methods annotated with @StreamListener, a conversion will be applied automatically if the argument requires it.
For example, let’s consider a message with the String content {"greeting":"Hello, world"} and a content-type header of application/json is received on the input channel.
+Let us consider the following application that receives it:
public class GreetingMessage {
+
+ String greeting;
+
+ public String getGreeting() {
+ return greeting;
+ }
+
+ public void setGreeting(String greeting) {
+ this.greeting = greeting;
+ }
+}
+
+@EnableBinding(Sink.class)
+@EnableAutoConfiguration
+public static class GreetingSink {
+
+ @StreamListener(Sink.INPUT)
+ public void receive(Greeting greeting) {
+ // handle Greeting
+ }
+ }
+The argument of the method will be populated automatically with the POJO containing the unmarshalled form of the JSON String.
+Supposing that a design calls for the Time Source application to send data to the Log Sink application, you can use a common destination named ticktock for bindings within both applications.
Time Source will set the following property:
+Time Source (that has the channel name output) will set the following property:
Log Sink will set the following property:
+Log Sink (that has the channel name input) will set the following property:
An input binding is configured to receive partitioned data by setting its partitioned property, as well as the instanceIndex and instanceCount properties on the application itself, as in the following example:
An input binding (with the channel name input) is configured to receive partitioned data by setting its partitioned property, as well as the instanceIndex and instanceCount properties on the application itself, as in the following example:
@RunWith(SpringJUnit4ClassRunner.class)
+@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ExampleTest.MyProcessor.class)
@IntegrationTest({"server.port=-1"})
@DirtiesContext
@@ -7739,16 +8060,363 @@ If you want to use Grok together with the logs from Cloud Foundry you have to us
}
Often you do not want to store your logs in a text file but in a JSON file that Logstash can immediately pick. To do that you have to do the following (for readability
+we’re passing the dependencies in the groupId:artifactId:version notation.
Dependencies setup
+Ensure that Logback is on the classpath (ch.qos.logback:logback-core)
Add Logstash Logback encode - example for version 4.6 : net.logstash.logback:logstash-logback-encoder:4.6
Logback setup
+Below you can find an example of a Logback configuration (file named logback-spring.xml) that:
logs information from the application in a JSON format to a build/${spring.application.name}.json file
has commented out two additional appenders - console and standard log file
+has the same logging pattern as the one presented in the previous section
+
+In general if you want to profit only from Spring Cloud Sleuth without the Zipkin integration just add -the spring-cloud-starter-sleuth module to your project.
+If you want to profit only from Spring Cloud Sleuth without the Zipkin integration just add
+the spring-cloud-starter-sleuth module to your project.
<dependencyManagement> (1)
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-dependencies</artifactId>
+ <version>Brixton.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+</dependencyManagement>
+
+<dependency> (2)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+</dependency>
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-starter-sleuth
dependencyManagement { (1)
+ imports {
+ mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
+ }
+}
+
+dependencies { (2)
+ compile "org.springframework.cloud:spring-cloud-starter-sleuth"
+}
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-starter-sleuth
If you want both Sleuth and Zipkin just add the spring-cloud-starter-zipkin dependency.
<dependencyManagement> (1)
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-dependencies</artifactId>
+ <version>Brixton.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+</dependencyManagement>
+
+<dependency> (2)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-zipkin</artifactId>
+</dependency>
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-starter-zipkin
dependencyManagement { (1)
+ imports {
+ mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
+ }
+}
+
+dependencies { (2)
+ compile "org.springframework.cloud:spring-cloud-starter-zipkin"
+}
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-starter-zipkin
If you want both Sleuth and Zipkin just add the spring-cloud-sleuth-stream dependency.
<dependencyManagement> (1)
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-dependencies</artifactId>
+ <version>Brixton.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+</dependencyManagement>
+
+<dependency> (2)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-sleuth-stream</artifactId>
+</dependency>
+<dependency> (3)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+</dependency>
+<!-- EXAMPLE FOR RABBIT BINDING -->
+<dependency> (4)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
+</dependency>
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-sleuth-stream
Add the dependency to spring-cloud-starter-sleuth - that way all dependant dependencies will be downloaded
Add a binder (e.g. Rabbit binder) to tell Spring Cloud Stream what it should bind to
+dependencyManagement { (1)
+ imports {
+ mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
+ }
+}
+
+dependencies {
+ compile "org.springframework.cloud:spring-cloud-sleuth-stream" (2)
+ compile "org.springframework.cloud:spring-cloud-starter-sleuth" (3)
+ // Example for Rabbit binding
+ compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit" (4)
+}
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-sleuth-stream
Add the dependency to spring-cloud-starter-sleuth - that way all dependant dependencies will be downloaded
Add a binder (e.g. Rabbit binder) to tell Spring Cloud Stream what it should bind to
+If you want to start a Spring Cloud Sleuth Stream Zipkin collector just add the spring-cloud-sleuth-zipkin-stream
+dependency
<dependencyManagement> (1)
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-dependencies</artifactId>
+ <version>Brixton.RELEASE</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+</dependencyManagement>
+
+<dependency> (2)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
+</dependency>
+<dependency> (3)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-starter-sleuth</artifactId>
+</dependency>
+<!-- EXAMPLE FOR RABBIT BINDING -->
+<dependency> (4)
+ <groupId>org.springframework.cloud</groupId>
+ <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
+</dependency>
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-sleuth-zipkin-stream
Add the dependency to spring-cloud-starter-sleuth - that way all dependant dependencies will be downloaded
Add a binder (e.g. Rabbit binder) to tell Spring Cloud Stream what it should bind to
+dependencyManagement { (1)
+ imports {
+ mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.RELEASE"
+ }
+}
+
+dependencies {
+ compile "org.springframework.cloud:spring-cloud-sleuth-zipkin-stream" (2)
+ compile "org.springframework.cloud:spring-cloud-starter-sleuth" (3)
+ // Example for Rabbit binding
+ compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit" (4)
+}
+In order not to pick versions by yourself it’s much better if you add the dependency management via +the Spring BOM
+Add the dependency to spring-cloud-sleuth-zipkin-stream
Add the dependency to spring-cloud-starter-sleuth - that way all dependant dependencies will be downloaded
Add a binder (e.g. Rabbit binder) to tell Spring Cloud Stream what it should bind to
+If you want both Sleuth and Zipkin just add the spring-cloud-starter-zipkin dependency.
+and then just annotate your main class with @EnableZipkinStreamServer annotation:
+Action0 instances into their Sleuth representative -
the TraceAction. The hook either starts or continues a span depending on the fact whether tracing was already going
on before the Action was scheduled. To disable the custom RxJavaSchedulersHook set the spring.sleuth.rxjava.schedulers.hook.enabled to false.
You can define a list of regular expressions for thread names, for which you don’t want a Span to be created. Just provide a comma separated list
+of regular expressions in the spring.sleuth.rxjava.schedulers.ignoredthreads property.
To install, make sure you have Spring Boot CLI -(1.3.0 or better):
+(1.3.5 or better):$ spring version -Spring CLI v1.3.2.RELEASE+Spring CLI v1.3.5.RELEASE
$ sdk install springboot 1.3.2.RELEASE
-$ sdk use springboot 1.3.2.RELEASE
+$ sdk install springboot 1.3.5.RELEASE
+$ sdk use springboot 1.3.5.RELEASE
$ mvn install
-$ spring install org.springframework.cloud:spring-cloud-cli:1.1.0.RC1
+$ spring install org.springframework.cloud:spring-cloud-cli:1.1.0.RELEASE