Sync docs from master to gh-pages
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>3. Addressing all instances of a service</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__addressing_an_instance.html" title="2. Addressing an Instance"><link rel="next" href="multi__service_id_must_be_unique.html" title="4. Service ID must be unique"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Addressing all instances of a service</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__addressing_an_instance.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__service_id_must_be_unique.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_all_instances_of_a_service" href="#_addressing_all_instances_of_a_service"></a>3. Addressing all instances of a service</h1></div></div></div><p>The "destination" parameter is used in a Spring <code class="literal">PathMatcher</code> (with the path separator as a colon <code class="literal">:</code>) to determine if an instance will process the message. Using the example from above, "/bus/refresh?destination=customers:**" will target all instances of the "customers" service regardless of the rest of the service ID.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__addressing_an_instance.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__service_id_must_be_unique.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. Addressing an Instance </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 4. Service ID must be unique</td></tr></table></div></body></html>
|
||||
<title>3. Addressing All Instances of a Service</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__addressing_an_instance.html" title="2. Addressing an Instance"><link rel="next" href="multi__service_id_must_be_unique.html" title="4. Service ID Must Be Unique"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">3. Addressing All Instances of a Service</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__addressing_an_instance.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__service_id_must_be_unique.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_all_instances_of_a_service" href="#_addressing_all_instances_of_a_service"></a>3. Addressing All Instances of a Service</h1></div></div></div><p>The “destination” parameter is used in a Spring <code class="literal">PathMatcher</code> (with the path separator
|
||||
as a colon — <code class="literal">:</code>) to determine if an instance processes the message. Using the example
|
||||
from earlier, <code class="literal">/bus/refresh?destination=customers:**</code> targets all instances of the
|
||||
“customers” service regardless of the rest of the service ID.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__addressing_an_instance.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__service_id_must_be_unique.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. Addressing an Instance </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 4. Service ID Must Be Unique</td></tr></table></div></body></html>
|
||||
@@ -1,3 +1,12 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>2. Addressing an Instance</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__quick_start.html" title="1. Quick Start"><link rel="next" href="multi__addressing_all_instances_of_a_service.html" title="3. Addressing all instances of a service"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. Addressing an Instance</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__quick_start.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__addressing_all_instances_of_a_service.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_an_instance" href="#_addressing_an_instance"></a>2. Addressing an Instance</h1></div></div></div><p>Each instance of the application has a service ID, whose value can be set using <code class="literal">spring.cloud.bus.id</code>, and whose value is expected to be a colon-separated list of identifiers, in order of least specific to most specific. The default value is constructed from the environment as a combination of the <code class="literal">spring.application.name</code> and <code class="literal">server.port</code> (or <code class="literal">spring.application.index</code> if set). The default value of the ID is constructed in the form <code class="literal">app:index:id</code> where:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">app</code> is the <code class="literal">vcap.application.name</code> if it exists, or <code class="literal">spring.application.name</code></li><li class="listitem"><code class="literal">index</code> is the <code class="literal">vcap.application.instance_index</code> if it exists, or else <code class="literal">spring.application.index</code>, or else <code class="literal">local.server.port</code> (or <code class="literal">server.port</code> or <code class="literal">0</code>).</li><li class="listitem"><code class="literal">id</code> is the <code class="literal">vcap.application.instance_id</code> if it exists, or else a random value.</li></ul></div><p>The HTTP endpoints accept a "destination" parameter, e.g. "/bus/refresh?destination=customers:9000", where the destination is a service ID. If the ID is owned by an instance on the Bus then it will process the message and all other instances will ignore it.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__quick_start.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__addressing_all_instances_of_a_service.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1. Quick Start </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 3. Addressing all instances of a service</td></tr></table></div></body></html>
|
||||
<title>2. Addressing an Instance</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__quick_start.html" title="1. Quick Start"><link rel="next" href="multi__addressing_all_instances_of_a_service.html" title="3. Addressing All Instances of a Service"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2. Addressing an Instance</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__quick_start.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__addressing_all_instances_of_a_service.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_an_instance" href="#_addressing_an_instance"></a>2. Addressing an Instance</h1></div></div></div><p>Each instance of the application has a service ID, whose value can be set with
|
||||
<code class="literal">spring.cloud.bus.id</code> and whose value is expected to be a colon-separated list of
|
||||
identifiers, in order from least specific to most specific. The default value is
|
||||
constructed from the environment as a combination of the <code class="literal">spring.application.name</code> and
|
||||
<code class="literal">server.port</code> (or <code class="literal">spring.application.index</code>, if set). The default value of the ID is
|
||||
constructed in the form of <code class="literal">app:index:id</code>, where:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">app</code> is the <code class="literal">vcap.application.name</code>, if it exists, or <code class="literal">spring.application.name</code></li><li class="listitem"><code class="literal">index</code> is the <code class="literal">vcap.application.instance_index</code>, if it exists,
|
||||
<code class="literal">spring.application.index</code>, <code class="literal">local.server.port</code>, <code class="literal">server.port</code>, or <code class="literal">0</code> (in that order).</li><li class="listitem"><code class="literal">id</code> is the <code class="literal">vcap.application.instance_id</code>, if it exists, or a random value.</li></ul></div><p>The HTTP endpoints accept a “destination” parameter, such as
|
||||
<code class="literal">/bus/refresh?destination=customers:9000</code>, where <code class="literal">destination</code> is a service ID. If the ID
|
||||
is owned by an instance on the bus, it processes the message, and all other instances
|
||||
ignore it.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__quick_start.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__addressing_all_instances_of_a_service.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1. Quick Start </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 3. Addressing All Instances of a Service</td></tr></table></div></body></html>
|
||||
@@ -1,28 +1,27 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>7. Broadcasting Your Own Events</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__tracing_bus_events.html" title="6. Tracing Bus Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7. Broadcasting Your Own Events</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__tracing_bus_events.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_broadcasting_your_own_events" href="#_broadcasting_your_own_events"></a>7. Broadcasting Your Own Events</h1></div></div></div><p>The Bus can carry any event of type <code class="literal">RemoteApplicationEvent</code>, but the
|
||||
default transport is JSON and the deserializer needs to know which
|
||||
types are going to be used ahead of time. To register a new type it
|
||||
needs to be in a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>.</p><p>To customise the event name you can use <code class="literal">@JsonTypeName</code> on your custom class
|
||||
or rely on the default strategy which is to use the simple name of the class.
|
||||
Note that both the producer and the consumer will need access to the class
|
||||
definition.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_events_in_custom_packages" href="#_registering_events_in_custom_packages"></a>7.1 Registering events in custom packages</h2></div></div></div><p>If you cannot or don’t want to use a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>
|
||||
for your custom events, you must specify which packages to scan for events of
|
||||
type <code class="literal">RemoteApplicationEvent</code> using <code class="literal">@RemoteApplicationEventScan</code>. Packages
|
||||
specified with <code class="literal">@RemoteApplicationEventScan</code> include subpackages.</p><p>For example, if you have a custom event called <code class="literal">FooEvent</code>:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
<title>7. Broadcasting Your Own Events</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__tracing_bus_events.html" title="6. Tracing Bus Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7. Broadcasting Your Own Events</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__tracing_bus_events.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> </td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_broadcasting_your_own_events" href="#_broadcasting_your_own_events"></a>7. Broadcasting Your Own Events</h1></div></div></div><p>The Bus can carry any event of type <code class="literal">RemoteApplicationEvent</code>. The default transport is
|
||||
JSON, and the deserializer needs to know which types are going to be used ahead of time.
|
||||
To register a new type, you must put it in a subpackage of
|
||||
<code class="literal">org.springframework.cloud.bus.event</code>.</p><p>To customise the event name, you can use <code class="literal">@JsonTypeName</code> on your custom class or rely on
|
||||
the default strategy, which is to use the simple name of the class.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Both the producer and the consumer need access to the class definition.</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_events_in_custom_packages" href="#_registering_events_in_custom_packages"></a>7.1 Registering events in custom packages</h2></div></div></div><p>If you cannot or do not want to use a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>
|
||||
for your custom events, you must specify which packages to scan for events of type
|
||||
<code class="literal">RemoteApplicationEvent</code> by using the <code class="literal">@RemoteApplicationEventScan</code> annotation. Packages
|
||||
specified with <code class="literal">@RemoteApplicationEventScan</code> include subpackages.</p><p>For example, consider the following custom event, called <code class="literal">MyEvent</code>:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> FooEvent <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> RemoteApplicationEvent {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> MyEvent <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> RemoteApplicationEvent {
|
||||
...
|
||||
}</pre><p>you can register this event with the deserializer in the following way:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
}</pre><p>You can register that event with the deserializer in the following way:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@RemoteApplicationEventScan</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> BusConfiguration {
|
||||
...
|
||||
}</pre><p>Without specifying a value, the package of the class where <code class="literal">@RemoteApplicationEventScan</code>
|
||||
is used will be registered. In this example <code class="literal">com.acme</code> will be registered using the
|
||||
package of <code class="literal">BusConfiguration</code>.</p><p>You can also explicitly specify the packages to scan using the <code class="literal">value</code>, <code class="literal">basePackages</code> or
|
||||
<code class="literal">basePackageClasses</code> properties on <code class="literal">@RemoteApplicationEventScan</code>. For example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
is used is registered. In this example, <code class="literal">com.acme</code> is registered by using the package of
|
||||
<code class="literal">BusConfiguration</code>.</p><p>You can also explicitly specify the packages to scan by using the <code class="literal">value</code>, <code class="literal">basePackages</code>
|
||||
or <code class="literal">basePackageClasses</code> properties on <code class="literal">@RemoteApplicationEventScan</code>, as shown in the
|
||||
following example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//@RemoteApplicationEventScan({"com.acme", "foo.bar"})</span>
|
||||
@@ -30,7 +29,6 @@ package of <code class="literal">BusConfiguration</code>.</p><p>You can also exp
|
||||
<em><span class="hl-annotation" style="color: gray">@RemoteApplicationEventScan(basePackageClasses = BusConfiguration.class)</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> BusConfiguration {
|
||||
...
|
||||
}</pre><p>All examples of <code class="literal">@RemoteApplicationEventScan</code> above are equivalent,
|
||||
in that the <code class="literal">com.acme</code> package will be registered by explicitly specifying the
|
||||
packages on <code class="literal">@RemoteApplicationEventScan</code>. Note, you can specify multiple base
|
||||
packages to scan.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__tracing_bus_events.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top">6. Tracing Bus Events </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
}</pre><p>All of the preceding examples of <code class="literal">@RemoteApplicationEventScan</code> are equivalent, in that the
|
||||
<code class="literal">com.acme</code> package is registered by explicitly specifying the packages on
|
||||
<code class="literal">@RemoteApplicationEventScan</code>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>You can specify multiple base packages to scan.</p></td></tr></table></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__tracing_bus_events.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top">6. Tracing Bus Events </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
@@ -1,17 +1,13 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>5. Customizing the Message Broker</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__service_id_must_be_unique.html" title="4. Service ID must be unique"><link rel="next" href="multi__tracing_bus_events.html" title="6. Tracing Bus Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5. Customizing the Message Broker</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__service_id_must_be_unique.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__tracing_bus_events.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizing_the_message_broker" href="#_customizing_the_message_broker"></a>5. Customizing the Message Broker</h1></div></div></div><p>Spring Cloud Bus uses
|
||||
<a class="link" href="https://cloud.spring.io/spring-cloud-stream" target="_top">Spring Cloud Stream</a> to
|
||||
broadcast the messages so to get messages to flow you only need to
|
||||
include the binder implementation of your choice in the
|
||||
classpath. There are convenient starters specifically for the bus with
|
||||
AMQP (RabbitMQ) and Kafka
|
||||
(<code class="literal">spring-cloud-starter-bus-[amqp,kafka]</code>). Generally speaking
|
||||
Spring Cloud Stream relies on Spring Boot autoconfiguration
|
||||
conventions for configuring middleware, so for instance the AMQP
|
||||
broker address can be changed with <code class="literal">spring.rabbitmq.*</code>
|
||||
configuration properties. Spring Cloud Bus has a handful of native
|
||||
configuration properties in <code class="literal">spring.cloud.bus.*</code>
|
||||
(e.g. <code class="literal">spring.cloud.bus.destination</code> is the name of the topic to use
|
||||
the the externall middleware). Normally the defaults will suffice.</p><p>To lean more about how to customize the message broker settings
|
||||
consult the Spring Cloud Stream documentation.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__service_id_must_be_unique.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__tracing_bus_events.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Service ID must be unique </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 6. Tracing Bus Events</td></tr></table></div></body></html>
|
||||
<title>5. Customizing the Message Broker</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__service_id_must_be_unique.html" title="4. Service ID Must Be Unique"><link rel="next" href="multi__tracing_bus_events.html" title="6. Tracing Bus Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5. Customizing the Message Broker</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__service_id_must_be_unique.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__tracing_bus_events.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizing_the_message_broker" href="#_customizing_the_message_broker"></a>5. Customizing the Message Broker</h1></div></div></div><p>Spring Cloud Bus uses <a class="link" href="https://cloud.spring.io/spring-cloud-stream" target="_top">Spring Cloud Stream</a> to
|
||||
broadcast the messages. So, to get messages to flow, you need only include the binder
|
||||
implementation of your choice in the classpath. There are convenient starters for the bus
|
||||
with AMQP (RabbitMQ) and Kafka (<code class="literal">spring-cloud-starter-bus-[amqp|kafka]</code>). Generally
|
||||
speaking, Spring Cloud Stream relies on Spring Boot autoconfiguration conventions for
|
||||
configuring middleware. For instance, the AMQP broker address can be changed with
|
||||
<code class="literal">spring.rabbitmq.*</code> configuration properties. Spring Cloud Bus has a handful of
|
||||
native configuration properties in <code class="literal">spring.cloud.bus.*</code> (for example,
|
||||
<code class="literal">spring.cloud.bus.destination</code> is the name of the topic to use as the external
|
||||
middleware). Normally, the defaults suffice.</p><p>To learn more about how to customize the message broker settings, consult the Spring Cloud
|
||||
Stream documentation.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__service_id_must_be_unique.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__tracing_bus_events.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Service ID Must Be Unique </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 6. Tracing Bus Events</td></tr></table></div></body></html>
|
||||
@@ -1,10 +1,23 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>1. Quick Start</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi_pr01.html" title=""><link rel="next" href="multi__addressing_an_instance.html" title="2. Addressing an Instance"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1. Quick Start</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_pr01.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__addressing_an_instance.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_quick_start" href="#_quick_start"></a>1. Quick Start</h1></div></div></div><p>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the classpath. All you need to do to enable the bus is to add <code class="literal">spring-cloud-starter-bus-amqp</code> or <code class="literal">spring-cloud-starter-bus-kafka</code> to your dependency management and Spring Cloud takes care of the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured: running on localhost you shouldn’t have to do anything, but if you are running remotely use Spring Cloud Connectors, or Spring Boot conventions to define the broker credentials, e.g. for Rabbit</p><p><b>application.yml. </b>
|
||||
<title>1. Quick Start</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi_pr01.html" title=""><link rel="next" href="multi__addressing_an_instance.html" title="2. Addressing an Instance"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1. Quick Start</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_pr01.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__addressing_an_instance.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_quick_start" href="#_quick_start"></a>1. Quick Start</h1></div></div></div><p>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the
|
||||
classpath. To enable the bus, add <code class="literal">spring-cloud-starter-bus-amqp</code> or
|
||||
<code class="literal">spring-cloud-starter-bus-kafka</code> to your dependency management. Spring Cloud takes care of
|
||||
the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured. When
|
||||
running on localhost, you need not do anything. If you run remotely, use Spring Cloud
|
||||
Connectors or Spring Boot conventions to define the broker credentials, as shown in the
|
||||
following example for Rabbit:</p><p><b>application.yml. </b>
|
||||
</p><pre class="screen">spring:
|
||||
rabbitmq:
|
||||
host: mybroker.com
|
||||
port: 5672
|
||||
username: user
|
||||
password: secret</pre><p>
|
||||
</p><p>The bus currently supports sending messages to all nodes listening or all nodes for a particular service (as defined by Eureka). More selector criteria may be added in the future (ie. only service X nodes in data center Y, etc…​). There are also some http endpoints under the <code class="literal">/bus/*</code> actuator namespace. There are currently two implemented. The first, <code class="literal">/bus/env</code>, sends key/value pairs to update each node’s Spring Environment. The second, <code class="literal">/bus/refresh</code>, will reload each application’s configuration, just as if they had all been pinged on their <code class="literal">/refresh</code> endpoint.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>The Bus starters cover Rabbit and Kafka, because those are the two most common implementations, but Spring Cloud Stream is quite flexible and binder will work combined with <code class="literal">spring-cloud-bus</code>.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_pr01.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__addressing_an_instance.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 2. Addressing an Instance</td></tr></table></div></body></html>
|
||||
</p><p>The bus currently supports sending messages to all nodes listening or all nodes for a
|
||||
particular service (as defined by Eureka). The <code class="literal">/bus/*</code> actuator namespace has some HTTP
|
||||
endpoints. Currently, two are implemented. The first, <code class="literal">/bus/env</code>, sends key/value pairs to
|
||||
update each node’s Spring Environment. The second, <code class="literal">/bus/refresh</code>, reloads each
|
||||
application’s configuration, as though they had all been pinged on their <code class="literal">/refresh</code>
|
||||
endpoint.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>The Spring Cloud Bus starters cover Rabbit and Kafka, because those are the two most
|
||||
common implementations. However, Spring Cloud Stream is quite flexible, and the binder
|
||||
works with <code class="literal">spring-cloud-bus</code>.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_pr01.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__addressing_an_instance.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 2. Addressing an Instance</td></tr></table></div></body></html>
|
||||
@@ -1,3 +1,9 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>4. Service ID must be unique</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__addressing_all_instances_of_a_service.html" title="3. Addressing all instances of a service"><link rel="next" href="multi__customizing_the_message_broker.html" title="5. Customizing the Message Broker"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Service ID must be unique</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__addressing_all_instances_of_a_service.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__customizing_the_message_broker.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_service_id_must_be_unique" href="#_service_id_must_be_unique"></a>4. Service ID must be unique</h1></div></div></div><p>The bus tries to eliminate processing an event twice, once from the original <code class="literal">ApplicationEvent</code> and once from the queue. To do this, it checks the sending service ID againts the current service ID. If multiple instances of a service have the same ID, events will not be processed. Running on a local machine, each service will be on a different port and that will be part of the ID. Cloud Foundry supplies an index to differentiate. To ensure that the ID is unique outside Cloud Foundry, set <code class="literal">spring.application.index</code> to something unique for each instance of a service.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__addressing_all_instances_of_a_service.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__customizing_the_message_broker.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Addressing all instances of a service </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 5. Customizing the Message Broker</td></tr></table></div></body></html>
|
||||
<title>4. Service ID Must Be Unique</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__addressing_all_instances_of_a_service.html" title="3. Addressing All Instances of a Service"><link rel="next" href="multi__customizing_the_message_broker.html" title="5. Customizing the Message Broker"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Service ID Must Be Unique</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__addressing_all_instances_of_a_service.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__customizing_the_message_broker.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_service_id_must_be_unique" href="#_service_id_must_be_unique"></a>4. Service ID Must Be Unique</h1></div></div></div><p>The bus tries twice to eliminate processing an event — once from the original
|
||||
<code class="literal">ApplicationEvent</code> and once from the queue. To do so, it checks the sending service ID
|
||||
against the current service ID. If multiple instances of a service have the same ID,
|
||||
events are not processed. When running on a local machine, each service is on a different
|
||||
port, and that port is part of the ID. Cloud Foundry supplies an index to differentiate.
|
||||
To ensure that the ID is unique outside Cloud Foundry, set <code class="literal">spring.application.index</code> to
|
||||
something unique for each instance of a service.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__addressing_all_instances_of_a_service.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__customizing_the_message_broker.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Addressing All Instances of a Service </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 5. Customizing the Message Broker</td></tr></table></div></body></html>
|
||||
@@ -1,10 +1,9 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>6. Tracing Bus Events</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__customizing_the_message_broker.html" title="5. Customizing the Message Broker"><link rel="next" href="multi__broadcasting_your_own_events.html" title="7. Broadcasting Your Own Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6. Tracing Bus Events</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__customizing_the_message_broker.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__broadcasting_your_own_events.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_tracing_bus_events" href="#_tracing_bus_events"></a>6. Tracing Bus Events</h1></div></div></div><p>Bus events (subclasses of <code class="literal">RemoteApplicationEvent</code>) can be traced by
|
||||
setting <code class="literal">spring.cloud.bus.trace.enabled=true</code>. If you do this then the
|
||||
Spring Boot <code class="literal">TraceRepository</code> (if it is present) will show each event
|
||||
sent and all the acks from each service instance. Example (from the
|
||||
<code class="literal">/trace</code> endpoint):</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<title>6. Tracing Bus Events</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi__customizing_the_message_broker.html" title="5. Customizing the Message Broker"><link rel="next" href="multi__broadcasting_your_own_events.html" title="7. Broadcasting Your Own Events"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6. Tracing Bus Events</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__customizing_the_message_broker.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__broadcasting_your_own_events.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_tracing_bus_events" href="#_tracing_bus_events"></a>6. Tracing Bus Events</h1></div></div></div><p>Bus events (subclasses of <code class="literal">RemoteApplicationEvent</code>) can be traced by setting
|
||||
<code class="literal">spring.cloud.bus.trace.enabled=true</code>. If you do so, the Spring Boot <code class="literal">TraceRepository</code>
|
||||
(if it is present) shows each event sent and all the acks from each service instance. The
|
||||
following example comes from the <code class="literal">/trace</code> endpoint:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"timestamp"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"2015-11-26T10:24:44.411+0000"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"info"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"signal"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"spring.cloud.bus.ack"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
@@ -33,11 +32,11 @@ sent and all the acks from each service instance. Example (from the
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"origin"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"customers:9000"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"destination"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"*:**"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>This trace shows that a <code class="literal">RefreshRemoteApplicationEvent</code> was sent from
|
||||
<code class="literal">customers:9000</code>, broadcast to all services, and it was received
|
||||
(acked) by <code class="literal">customers:9000</code> and <code class="literal">stores:8081</code>.</p><p>To handle the ack signals yourself you could add an <code class="literal">@EventListener</code>
|
||||
for the <code class="literal">AckRemoteApplicationEvent</code> and <code class="literal">SentApplicationEvent</code> types
|
||||
to your app (and enable tracing). Or you could tap into the
|
||||
<code class="literal">TraceRepository</code> and mine the data from there.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Any Bus application can trace acks, but sometimes it will be
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>The preceding trace shows that a <code class="literal">RefreshRemoteApplicationEvent</code> was sent from
|
||||
<code class="literal">customers:9000</code>, broadcast to all services, and received (acked) by <code class="literal">customers:9000</code> and
|
||||
<code class="literal">stores:8081</code>.</p><p>To handle the ack signals yourself, you could add an <code class="literal">@EventListener</code> for the
|
||||
<code class="literal">AckRemoteApplicationEvent</code> and <code class="literal">SentApplicationEvent</code> types to your app (and enable
|
||||
tracing). Alternatively, you could tap into the <code class="literal">TraceRepository</code> and mine the data from
|
||||
there.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Any Bus application can trace acks. However, sometimes, it is
|
||||
useful to do this in a central service that can do more complex
|
||||
queries on the data. Or forward it to a specialized tracing service.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__customizing_the_message_broker.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__broadcasting_your_own_events.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5. Customizing the Message Broker </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 7. Broadcasting Your Own Events</td></tr></table></div></body></html>
|
||||
queries on the data or forward it to a specialized tracing service.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__customizing_the_message_broker.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__broadcasting_your_own_events.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5. Customizing the Message Broker </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 7. Broadcasting Your Own Events</td></tr></table></div></body></html>
|
||||
@@ -1,3 +1,8 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title></title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="next" href="multi__quick_start.html" title="1. Quick Start"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-bus.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__quick_start.html">Next</a></td></tr></table><hr></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. A key idea is that the Bus is like a distributed Actuator for a Spring Boot application that is scaled out, but it can also be used as a communication channel between apps. Starters are provided for an AMQP broker as the transport or for Kafka, but the same basic feature set (and some more depending on the transport) is on the roadmap for other transports.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at <a class="link" href="https://github.com/spring-cloud/spring-cloud-config/tree/master/docs/src/main/asciidoc" target="_top">github</a>.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-bus.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__quick_start.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Spring Cloud Bus </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 1. Quick Start</td></tr></table></div></body></html>
|
||||
<title></title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="up" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="prev" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="next" href="multi__quick_start.html" title="1. Quick Start"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center"></th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi_spring-cloud-bus.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__quick_start.html">Next</a></td></tr></table><hr></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Spring Cloud Bus links the nodes of a distributed system with a lightweight message
|
||||
broker. This broker can then be used to broadcast state changes (such as configuration
|
||||
changes) or other management instructions. A key idea is that the bus is like a
|
||||
distributed actuator for a Spring Boot application that is scaled out. However, it can
|
||||
also be used as a communication channel between apps. This project provides starters for
|
||||
either an AMQP broker or Kafka as the transport.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at <a class="link" href="https://github.com/spring-cloud/spring-cloud-config/tree/master/docs/src/main/asciidoc" target="_top">github</a>.</p></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi_spring-cloud-bus.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__quick_start.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Spring Cloud Bus </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-bus.html">Home</a></td><td width="40%" align="right" valign="top"> 1. Quick Start</td></tr></table></div></body></html>
|
||||
@@ -1,3 +1,3 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Spring Cloud Bus</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="next" href="multi_pr01.html" title=""></head><body class="firstpage" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Spring Cloud Bus</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr></table><hr></div><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Bus</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="multi_pr01.html"></a></span></dt><dt><span class="chapter"><a href="multi__quick_start.html">1. Quick Start</a></span></dt><dt><span class="chapter"><a href="multi__addressing_an_instance.html">2. Addressing an Instance</a></span></dt><dt><span class="chapter"><a href="multi__addressing_all_instances_of_a_service.html">3. Addressing all instances of a service</a></span></dt><dt><span class="chapter"><a href="multi__service_id_must_be_unique.html">4. Service ID must be unique</a></span></dt><dt><span class="chapter"><a href="multi__customizing_the_message_broker.html">5. Customizing the Message Broker</a></span></dt><dt><span class="chapter"><a href="multi__tracing_bus_events.html">6. Tracing Bus Events</a></span></dt><dt><span class="chapter"><a href="multi__broadcasting_your_own_events.html">7. Broadcasting Your Own Events</a></span></dt><dd><dl><dt><span class="section"><a href="multi__broadcasting_your_own_events.html#_registering_events_in_custom_packages">7.1. Registering events in custom packages</a></span></dt></dl></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
<title>Spring Cloud Bus</title><link rel="stylesheet" type="text/css" href="css/manual-multipage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="multi_spring-cloud-bus.html" title="Spring Cloud Bus"><link rel="next" href="multi_pr01.html" title=""></head><body class="firstpage" bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Spring Cloud Bus</th></tr><tr><td width="20%" align="left"> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr></table><hr></div><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Bus</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="multi_pr01.html"></a></span></dt><dt><span class="chapter"><a href="multi__quick_start.html">1. Quick Start</a></span></dt><dt><span class="chapter"><a href="multi__addressing_an_instance.html">2. Addressing an Instance</a></span></dt><dt><span class="chapter"><a href="multi__addressing_all_instances_of_a_service.html">3. Addressing All Instances of a Service</a></span></dt><dt><span class="chapter"><a href="multi__service_id_must_be_unique.html">4. Service ID Must Be Unique</a></span></dt><dt><span class="chapter"><a href="multi__customizing_the_message_broker.html">5. Customizing the Message Broker</a></span></dt><dt><span class="chapter"><a href="multi__tracing_bus_events.html">6. Tracing Bus Events</a></span></dt><dt><span class="chapter"><a href="multi__broadcasting_your_own_events.html">7. Broadcasting Your Own Events</a></span></dt><dd><dl><dt><span class="section"><a href="multi__broadcasting_your_own_events.html#_registering_events_in_custom_packages">7.1. Registering events in custom packages</a></span></dt></dl></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi_pr01.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"> </td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
@@ -1,31 +1,62 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>Spring Cloud Bus</title><link rel="stylesheet" type="text/css" href="css/manual-singlepage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Bus</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="#d0e9"></a></span></dt><dt><span class="chapter"><a href="#_quick_start">1. Quick Start</a></span></dt><dt><span class="chapter"><a href="#_addressing_an_instance">2. Addressing an Instance</a></span></dt><dt><span class="chapter"><a href="#_addressing_all_instances_of_a_service">3. Addressing all instances of a service</a></span></dt><dt><span class="chapter"><a href="#_service_id_must_be_unique">4. Service ID must be unique</a></span></dt><dt><span class="chapter"><a href="#_customizing_the_message_broker">5. Customizing the Message Broker</a></span></dt><dt><span class="chapter"><a href="#_tracing_bus_events">6. Tracing Bus Events</a></span></dt><dt><span class="chapter"><a href="#_broadcasting_your_own_events">7. Broadcasting Your Own Events</a></span></dt><dd><dl><dt><span class="section"><a href="#_registering_events_in_custom_packages">7.1. Registering events in custom packages</a></span></dt></dl></dd></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. A key idea is that the Bus is like a distributed Actuator for a Spring Boot application that is scaled out, but it can also be used as a communication channel between apps. Starters are provided for an AMQP broker as the transport or for Kafka, but the same basic feature set (and some more depending on the transport) is on the roadmap for other transports.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at <a class="link" href="https://github.com/spring-cloud/spring-cloud-config/tree/master/docs/src/main/asciidoc" target="_top">github</a>.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_quick_start" href="#_quick_start"></a>1. Quick Start</h1></div></div></div><p>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the classpath. All you need to do to enable the bus is to add <code class="literal">spring-cloud-starter-bus-amqp</code> or <code class="literal">spring-cloud-starter-bus-kafka</code> to your dependency management and Spring Cloud takes care of the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured: running on localhost you shouldn’t have to do anything, but if you are running remotely use Spring Cloud Connectors, or Spring Boot conventions to define the broker credentials, e.g. for Rabbit</p><p><b>application.yml. </b>
|
||||
<title>Spring Cloud Bus</title><link rel="stylesheet" type="text/css" href="css/manual-singlepage.css"><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div lang="en" class="book"><div class="titlepage"><div><div><h1 class="title"><a name="d0e3"></a>Spring Cloud Bus</h1></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="preface"><a href="#d0e9"></a></span></dt><dt><span class="chapter"><a href="#_quick_start">1. Quick Start</a></span></dt><dt><span class="chapter"><a href="#_addressing_an_instance">2. Addressing an Instance</a></span></dt><dt><span class="chapter"><a href="#_addressing_all_instances_of_a_service">3. Addressing All Instances of a Service</a></span></dt><dt><span class="chapter"><a href="#_service_id_must_be_unique">4. Service ID Must Be Unique</a></span></dt><dt><span class="chapter"><a href="#_customizing_the_message_broker">5. Customizing the Message Broker</a></span></dt><dt><span class="chapter"><a href="#_tracing_bus_events">6. Tracing Bus Events</a></span></dt><dt><span class="chapter"><a href="#_broadcasting_your_own_events">7. Broadcasting Your Own Events</a></span></dt><dd><dl><dt><span class="section"><a href="#_registering_events_in_custom_packages">7.1. Registering events in custom packages</a></span></dt></dl></dd></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e9" href="#d0e9"></a></h1></div></div></div><p>Spring Cloud Bus links the nodes of a distributed system with a lightweight message
|
||||
broker. This broker can then be used to broadcast state changes (such as configuration
|
||||
changes) or other management instructions. A key idea is that the bus is like a
|
||||
distributed actuator for a Spring Boot application that is scaled out. However, it can
|
||||
also be used as a communication channel between apps. This project provides starters for
|
||||
either an AMQP broker or Kafka as the transport.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at <a class="link" href="https://github.com/spring-cloud/spring-cloud-config/tree/master/docs/src/main/asciidoc" target="_top">github</a>.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_quick_start" href="#_quick_start"></a>1. Quick Start</h1></div></div></div><p>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the
|
||||
classpath. To enable the bus, add <code class="literal">spring-cloud-starter-bus-amqp</code> or
|
||||
<code class="literal">spring-cloud-starter-bus-kafka</code> to your dependency management. Spring Cloud takes care of
|
||||
the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured. When
|
||||
running on localhost, you need not do anything. If you run remotely, use Spring Cloud
|
||||
Connectors or Spring Boot conventions to define the broker credentials, as shown in the
|
||||
following example for Rabbit:</p><p><b>application.yml. </b>
|
||||
</p><pre class="screen">spring:
|
||||
rabbitmq:
|
||||
host: mybroker.com
|
||||
port: 5672
|
||||
username: user
|
||||
password: secret</pre><p>
|
||||
</p><p>The bus currently supports sending messages to all nodes listening or all nodes for a particular service (as defined by Eureka). More selector criteria may be added in the future (ie. only service X nodes in data center Y, etc…​). There are also some http endpoints under the <code class="literal">/bus/*</code> actuator namespace. There are currently two implemented. The first, <code class="literal">/bus/env</code>, sends key/value pairs to update each node’s Spring Environment. The second, <code class="literal">/bus/refresh</code>, will reload each application’s configuration, just as if they had all been pinged on their <code class="literal">/refresh</code> endpoint.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>The Bus starters cover Rabbit and Kafka, because those are the two most common implementations, but Spring Cloud Stream is quite flexible and binder will work combined with <code class="literal">spring-cloud-bus</code>.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_an_instance" href="#_addressing_an_instance"></a>2. Addressing an Instance</h1></div></div></div><p>Each instance of the application has a service ID, whose value can be set using <code class="literal">spring.cloud.bus.id</code>, and whose value is expected to be a colon-separated list of identifiers, in order of least specific to most specific. The default value is constructed from the environment as a combination of the <code class="literal">spring.application.name</code> and <code class="literal">server.port</code> (or <code class="literal">spring.application.index</code> if set). The default value of the ID is constructed in the form <code class="literal">app:index:id</code> where:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">app</code> is the <code class="literal">vcap.application.name</code> if it exists, or <code class="literal">spring.application.name</code></li><li class="listitem"><code class="literal">index</code> is the <code class="literal">vcap.application.instance_index</code> if it exists, or else <code class="literal">spring.application.index</code>, or else <code class="literal">local.server.port</code> (or <code class="literal">server.port</code> or <code class="literal">0</code>).</li><li class="listitem"><code class="literal">id</code> is the <code class="literal">vcap.application.instance_id</code> if it exists, or else a random value.</li></ul></div><p>The HTTP endpoints accept a "destination" parameter, e.g. "/bus/refresh?destination=customers:9000", where the destination is a service ID. If the ID is owned by an instance on the Bus then it will process the message and all other instances will ignore it.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_all_instances_of_a_service" href="#_addressing_all_instances_of_a_service"></a>3. Addressing all instances of a service</h1></div></div></div><p>The "destination" parameter is used in a Spring <code class="literal">PathMatcher</code> (with the path separator as a colon <code class="literal">:</code>) to determine if an instance will process the message. Using the example from above, "/bus/refresh?destination=customers:**" will target all instances of the "customers" service regardless of the rest of the service ID.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_service_id_must_be_unique" href="#_service_id_must_be_unique"></a>4. Service ID must be unique</h1></div></div></div><p>The bus tries to eliminate processing an event twice, once from the original <code class="literal">ApplicationEvent</code> and once from the queue. To do this, it checks the sending service ID againts the current service ID. If multiple instances of a service have the same ID, events will not be processed. Running on a local machine, each service will be on a different port and that will be part of the ID. Cloud Foundry supplies an index to differentiate. To ensure that the ID is unique outside Cloud Foundry, set <code class="literal">spring.application.index</code> to something unique for each instance of a service.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizing_the_message_broker" href="#_customizing_the_message_broker"></a>5. Customizing the Message Broker</h1></div></div></div><p>Spring Cloud Bus uses
|
||||
<a class="link" href="https://cloud.spring.io/spring-cloud-stream" target="_top">Spring Cloud Stream</a> to
|
||||
broadcast the messages so to get messages to flow you only need to
|
||||
include the binder implementation of your choice in the
|
||||
classpath. There are convenient starters specifically for the bus with
|
||||
AMQP (RabbitMQ) and Kafka
|
||||
(<code class="literal">spring-cloud-starter-bus-[amqp,kafka]</code>). Generally speaking
|
||||
Spring Cloud Stream relies on Spring Boot autoconfiguration
|
||||
conventions for configuring middleware, so for instance the AMQP
|
||||
broker address can be changed with <code class="literal">spring.rabbitmq.*</code>
|
||||
configuration properties. Spring Cloud Bus has a handful of native
|
||||
configuration properties in <code class="literal">spring.cloud.bus.*</code>
|
||||
(e.g. <code class="literal">spring.cloud.bus.destination</code> is the name of the topic to use
|
||||
the the externall middleware). Normally the defaults will suffice.</p><p>To lean more about how to customize the message broker settings
|
||||
consult the Spring Cloud Stream documentation.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_tracing_bus_events" href="#_tracing_bus_events"></a>6. Tracing Bus Events</h1></div></div></div><p>Bus events (subclasses of <code class="literal">RemoteApplicationEvent</code>) can be traced by
|
||||
setting <code class="literal">spring.cloud.bus.trace.enabled=true</code>. If you do this then the
|
||||
Spring Boot <code class="literal">TraceRepository</code> (if it is present) will show each event
|
||||
sent and all the acks from each service instance. Example (from the
|
||||
<code class="literal">/trace</code> endpoint):</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
</p><p>The bus currently supports sending messages to all nodes listening or all nodes for a
|
||||
particular service (as defined by Eureka). The <code class="literal">/bus/*</code> actuator namespace has some HTTP
|
||||
endpoints. Currently, two are implemented. The first, <code class="literal">/bus/env</code>, sends key/value pairs to
|
||||
update each node’s Spring Environment. The second, <code class="literal">/bus/refresh</code>, reloads each
|
||||
application’s configuration, as though they had all been pinged on their <code class="literal">/refresh</code>
|
||||
endpoint.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>The Spring Cloud Bus starters cover Rabbit and Kafka, because those are the two most
|
||||
common implementations. However, Spring Cloud Stream is quite flexible, and the binder
|
||||
works with <code class="literal">spring-cloud-bus</code>.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_an_instance" href="#_addressing_an_instance"></a>2. Addressing an Instance</h1></div></div></div><p>Each instance of the application has a service ID, whose value can be set with
|
||||
<code class="literal">spring.cloud.bus.id</code> and whose value is expected to be a colon-separated list of
|
||||
identifiers, in order from least specific to most specific. The default value is
|
||||
constructed from the environment as a combination of the <code class="literal">spring.application.name</code> and
|
||||
<code class="literal">server.port</code> (or <code class="literal">spring.application.index</code>, if set). The default value of the ID is
|
||||
constructed in the form of <code class="literal">app:index:id</code>, where:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><code class="literal">app</code> is the <code class="literal">vcap.application.name</code>, if it exists, or <code class="literal">spring.application.name</code></li><li class="listitem"><code class="literal">index</code> is the <code class="literal">vcap.application.instance_index</code>, if it exists,
|
||||
<code class="literal">spring.application.index</code>, <code class="literal">local.server.port</code>, <code class="literal">server.port</code>, or <code class="literal">0</code> (in that order).</li><li class="listitem"><code class="literal">id</code> is the <code class="literal">vcap.application.instance_id</code>, if it exists, or a random value.</li></ul></div><p>The HTTP endpoints accept a “destination” parameter, such as
|
||||
<code class="literal">/bus/refresh?destination=customers:9000</code>, where <code class="literal">destination</code> is a service ID. If the ID
|
||||
is owned by an instance on the bus, it processes the message, and all other instances
|
||||
ignore it.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_addressing_all_instances_of_a_service" href="#_addressing_all_instances_of_a_service"></a>3. Addressing All Instances of a Service</h1></div></div></div><p>The “destination” parameter is used in a Spring <code class="literal">PathMatcher</code> (with the path separator
|
||||
as a colon — <code class="literal">:</code>) to determine if an instance processes the message. Using the example
|
||||
from earlier, <code class="literal">/bus/refresh?destination=customers:**</code> targets all instances of the
|
||||
“customers” service regardless of the rest of the service ID.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_service_id_must_be_unique" href="#_service_id_must_be_unique"></a>4. Service ID Must Be Unique</h1></div></div></div><p>The bus tries twice to eliminate processing an event — once from the original
|
||||
<code class="literal">ApplicationEvent</code> and once from the queue. To do so, it checks the sending service ID
|
||||
against the current service ID. If multiple instances of a service have the same ID,
|
||||
events are not processed. When running on a local machine, each service is on a different
|
||||
port, and that port is part of the ID. Cloud Foundry supplies an index to differentiate.
|
||||
To ensure that the ID is unique outside Cloud Foundry, set <code class="literal">spring.application.index</code> to
|
||||
something unique for each instance of a service.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_customizing_the_message_broker" href="#_customizing_the_message_broker"></a>5. Customizing the Message Broker</h1></div></div></div><p>Spring Cloud Bus uses <a class="link" href="https://cloud.spring.io/spring-cloud-stream" target="_top">Spring Cloud Stream</a> to
|
||||
broadcast the messages. So, to get messages to flow, you need only include the binder
|
||||
implementation of your choice in the classpath. There are convenient starters for the bus
|
||||
with AMQP (RabbitMQ) and Kafka (<code class="literal">spring-cloud-starter-bus-[amqp|kafka]</code>). Generally
|
||||
speaking, Spring Cloud Stream relies on Spring Boot autoconfiguration conventions for
|
||||
configuring middleware. For instance, the AMQP broker address can be changed with
|
||||
<code class="literal">spring.rabbitmq.*</code> configuration properties. Spring Cloud Bus has a handful of
|
||||
native configuration properties in <code class="literal">spring.cloud.bus.*</code> (for example,
|
||||
<code class="literal">spring.cloud.bus.destination</code> is the name of the topic to use as the external
|
||||
middleware). Normally, the defaults suffice.</p><p>To learn more about how to customize the message broker settings, consult the Spring Cloud
|
||||
Stream documentation.</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_tracing_bus_events" href="#_tracing_bus_events"></a>6. Tracing Bus Events</h1></div></div></div><p>Bus events (subclasses of <code class="literal">RemoteApplicationEvent</code>) can be traced by setting
|
||||
<code class="literal">spring.cloud.bus.trace.enabled=true</code>. If you do so, the Spring Boot <code class="literal">TraceRepository</code>
|
||||
(if it is present) shows each event sent and all the acks from each service instance. The
|
||||
following example comes from the <code class="literal">/trace</code> endpoint:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"timestamp"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"2015-11-26T10:24:44.411+0000"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"info"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"signal"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"spring.cloud.bus.ack"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
@@ -54,36 +85,35 @@ sent and all the acks from each service instance. Example (from the
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"origin"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"customers:9000"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"destination"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"*:**"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>This trace shows that a <code class="literal">RefreshRemoteApplicationEvent</code> was sent from
|
||||
<code class="literal">customers:9000</code>, broadcast to all services, and it was received
|
||||
(acked) by <code class="literal">customers:9000</code> and <code class="literal">stores:8081</code>.</p><p>To handle the ack signals yourself you could add an <code class="literal">@EventListener</code>
|
||||
for the <code class="literal">AckRemoteApplicationEvent</code> and <code class="literal">SentApplicationEvent</code> types
|
||||
to your app (and enable tracing). Or you could tap into the
|
||||
<code class="literal">TraceRepository</code> and mine the data from there.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Any Bus application can trace acks, but sometimes it will be
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>The preceding trace shows that a <code class="literal">RefreshRemoteApplicationEvent</code> was sent from
|
||||
<code class="literal">customers:9000</code>, broadcast to all services, and received (acked) by <code class="literal">customers:9000</code> and
|
||||
<code class="literal">stores:8081</code>.</p><p>To handle the ack signals yourself, you could add an <code class="literal">@EventListener</code> for the
|
||||
<code class="literal">AckRemoteApplicationEvent</code> and <code class="literal">SentApplicationEvent</code> types to your app (and enable
|
||||
tracing). Alternatively, you could tap into the <code class="literal">TraceRepository</code> and mine the data from
|
||||
there.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Any Bus application can trace acks. However, sometimes, it is
|
||||
useful to do this in a central service that can do more complex
|
||||
queries on the data. Or forward it to a specialized tracing service.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_broadcasting_your_own_events" href="#_broadcasting_your_own_events"></a>7. Broadcasting Your Own Events</h1></div></div></div><p>The Bus can carry any event of type <code class="literal">RemoteApplicationEvent</code>, but the
|
||||
default transport is JSON and the deserializer needs to know which
|
||||
types are going to be used ahead of time. To register a new type it
|
||||
needs to be in a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>.</p><p>To customise the event name you can use <code class="literal">@JsonTypeName</code> on your custom class
|
||||
or rely on the default strategy which is to use the simple name of the class.
|
||||
Note that both the producer and the consumer will need access to the class
|
||||
definition.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_events_in_custom_packages" href="#_registering_events_in_custom_packages"></a>7.1 Registering events in custom packages</h2></div></div></div><p>If you cannot or don’t want to use a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>
|
||||
for your custom events, you must specify which packages to scan for events of
|
||||
type <code class="literal">RemoteApplicationEvent</code> using <code class="literal">@RemoteApplicationEventScan</code>. Packages
|
||||
specified with <code class="literal">@RemoteApplicationEventScan</code> include subpackages.</p><p>For example, if you have a custom event called <code class="literal">FooEvent</code>:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
queries on the data or forward it to a specialized tracing service.</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_broadcasting_your_own_events" href="#_broadcasting_your_own_events"></a>7. Broadcasting Your Own Events</h1></div></div></div><p>The Bus can carry any event of type <code class="literal">RemoteApplicationEvent</code>. The default transport is
|
||||
JSON, and the deserializer needs to know which types are going to be used ahead of time.
|
||||
To register a new type, you must put it in a subpackage of
|
||||
<code class="literal">org.springframework.cloud.bus.event</code>.</p><p>To customise the event name, you can use <code class="literal">@JsonTypeName</code> on your custom class or rely on
|
||||
the default strategy, which is to use the simple name of the class.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>Both the producer and the consumer need access to the class definition.</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_registering_events_in_custom_packages" href="#_registering_events_in_custom_packages"></a>7.1 Registering events in custom packages</h2></div></div></div><p>If you cannot or do not want to use a subpackage of <code class="literal">org.springframework.cloud.bus.event</code>
|
||||
for your custom events, you must specify which packages to scan for events of type
|
||||
<code class="literal">RemoteApplicationEvent</code> by using the <code class="literal">@RemoteApplicationEventScan</code> annotation. Packages
|
||||
specified with <code class="literal">@RemoteApplicationEventScan</code> include subpackages.</p><p>For example, consider the following custom event, called <code class="literal">MyEvent</code>:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> FooEvent <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> RemoteApplicationEvent {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> MyEvent <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">extends</span> RemoteApplicationEvent {
|
||||
...
|
||||
}</pre><p>you can register this event with the deserializer in the following way:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
}</pre><p>You can register that event with the deserializer in the following way:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@RemoteApplicationEventScan</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> BusConfiguration {
|
||||
...
|
||||
}</pre><p>Without specifying a value, the package of the class where <code class="literal">@RemoteApplicationEventScan</code>
|
||||
is used will be registered. In this example <code class="literal">com.acme</code> will be registered using the
|
||||
package of <code class="literal">BusConfiguration</code>.</p><p>You can also explicitly specify the packages to scan using the <code class="literal">value</code>, <code class="literal">basePackages</code> or
|
||||
<code class="literal">basePackageClasses</code> properties on <code class="literal">@RemoteApplicationEventScan</code>. For example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
is used is registered. In this example, <code class="literal">com.acme</code> is registered by using the package of
|
||||
<code class="literal">BusConfiguration</code>.</p><p>You can also explicitly specify the packages to scan by using the <code class="literal">value</code>, <code class="literal">basePackages</code>
|
||||
or <code class="literal">basePackageClasses</code> properties on <code class="literal">@RemoteApplicationEventScan</code>, as shown in the
|
||||
following example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">package</span> com.acme;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//@RemoteApplicationEventScan({"com.acme", "foo.bar"})</span>
|
||||
@@ -91,7 +121,6 @@ package of <code class="literal">BusConfiguration</code>.</p><p>You can also exp
|
||||
<em><span class="hl-annotation" style="color: gray">@RemoteApplicationEventScan(basePackageClasses = BusConfiguration.class)</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> BusConfiguration {
|
||||
...
|
||||
}</pre><p>All examples of <code class="literal">@RemoteApplicationEventScan</code> above are equivalent,
|
||||
in that the <code class="literal">com.acme</code> package will be registered by explicitly specifying the
|
||||
packages on <code class="literal">@RemoteApplicationEventScan</code>. Note, you can specify multiple base
|
||||
packages to scan.</p></div></div></div></body></html>
|
||||
}</pre><p>All of the preceding examples of <code class="literal">@RemoteApplicationEventScan</code> are equivalent, in that the
|
||||
<code class="literal">com.acme</code> package is registered by explicitly specifying the packages on
|
||||
<code class="literal">@RemoteApplicationEventScan</code>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Note"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="images/note.png"></td><th align="left">Note</th></tr><tr><td align="left" valign="top"><p>You can specify multiple base packages to scan.</p></td></tr></table></div></div></div></div></body></html>
|
||||
@@ -8,14 +8,25 @@
|
||||
</info>
|
||||
<preface>
|
||||
<title></title>
|
||||
<simpara>Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. A key idea is that the Bus is like a distributed Actuator for a Spring Boot application that is scaled out, but it can also be used as a communication channel between apps. Starters are provided for an AMQP broker as the transport or for Kafka, but the same basic feature set (and some more depending on the transport) is on the roadmap for other transports.</simpara>
|
||||
<simpara>Spring Cloud Bus links the nodes of a distributed system with a lightweight message
|
||||
broker. This broker can then be used to broadcast state changes (such as configuration
|
||||
changes) or other management instructions. A key idea is that the bus is like a
|
||||
distributed actuator for a Spring Boot application that is scaled out. However, it can
|
||||
also be used as a communication channel between apps. This project provides starters for
|
||||
either an AMQP broker or Kafka as the transport.</simpara>
|
||||
<note>
|
||||
<simpara>Spring Cloud is released under the non-restrictive Apache 2.0 license. If you would like to contribute to this section of the documentation or if you find an error, please find the source code and issue trackers in the project at <link xl:href="https://github.com/spring-cloud/spring-cloud-config/tree/master/docs/src/main/asciidoc">github</link>.</simpara>
|
||||
</note>
|
||||
</preface>
|
||||
<chapter xml:id="_quick_start">
|
||||
<title>Quick Start</title>
|
||||
<simpara>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the classpath. All you need to do to enable the bus is to add <literal>spring-cloud-starter-bus-amqp</literal> or <literal>spring-cloud-starter-bus-kafka</literal> to your dependency management and Spring Cloud takes care of the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured: running on localhost you shouldn’t have to do anything, but if you are running remotely use Spring Cloud Connectors, or Spring Boot conventions to define the broker credentials, e.g. for Rabbit</simpara>
|
||||
<simpara>Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the
|
||||
classpath. To enable the bus, add <literal>spring-cloud-starter-bus-amqp</literal> or
|
||||
<literal>spring-cloud-starter-bus-kafka</literal> to your dependency management. Spring Cloud takes care of
|
||||
the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured. When
|
||||
running on localhost, you need not do anything. If you run remotely, use Spring Cloud
|
||||
Connectors or Spring Boot conventions to define the broker credentials, as shown in the
|
||||
following example for Rabbit:</simpara>
|
||||
<formalpara>
|
||||
<title>application.yml</title>
|
||||
<para>
|
||||
@@ -27,61 +38,81 @@
|
||||
password: secret</screen>
|
||||
</para>
|
||||
</formalpara>
|
||||
<simpara>The bus currently supports sending messages to all nodes listening or all nodes for a particular service (as defined by Eureka). More selector criteria may be added in the future (ie. only service X nodes in data center Y, etc…​). There are also some http endpoints under the <literal>/bus/*</literal> actuator namespace. There are currently two implemented. The first, <literal>/bus/env</literal>, sends key/value pairs to update each node’s Spring Environment. The second, <literal>/bus/refresh</literal>, will reload each application’s configuration, just as if they had all been pinged on their <literal>/refresh</literal> endpoint.</simpara>
|
||||
<simpara>The bus currently supports sending messages to all nodes listening or all nodes for a
|
||||
particular service (as defined by Eureka). The <literal>/bus/*</literal> actuator namespace has some HTTP
|
||||
endpoints. Currently, two are implemented. The first, <literal>/bus/env</literal>, sends key/value pairs to
|
||||
update each node’s Spring Environment. The second, <literal>/bus/refresh</literal>, reloads each
|
||||
application’s configuration, as though they had all been pinged on their <literal>/refresh</literal>
|
||||
endpoint.</simpara>
|
||||
<note>
|
||||
<simpara>The Bus starters cover Rabbit and Kafka, because those are the two most common implementations, but Spring Cloud Stream is quite flexible and binder will work combined with <literal>spring-cloud-bus</literal>.</simpara>
|
||||
<simpara>The Spring Cloud Bus starters cover Rabbit and Kafka, because those are the two most
|
||||
common implementations. However, Spring Cloud Stream is quite flexible, and the binder
|
||||
works with <literal>spring-cloud-bus</literal>.</simpara>
|
||||
</note>
|
||||
</chapter>
|
||||
<chapter xml:id="_addressing_an_instance">
|
||||
<title>Addressing an Instance</title>
|
||||
<simpara>Each instance of the application has a service ID, whose value can be set using <literal>spring.cloud.bus.id</literal>, and whose value is expected to be a colon-separated list of identifiers, in order of least specific to most specific. The default value is constructed from the environment as a combination of the <literal>spring.application.name</literal> and <literal>server.port</literal> (or <literal>spring.application.index</literal> if set). The default value of the ID is constructed in the form <literal>app:index:id</literal> where:</simpara>
|
||||
<simpara>Each instance of the application has a service ID, whose value can be set with
|
||||
<literal>spring.cloud.bus.id</literal> and whose value is expected to be a colon-separated list of
|
||||
identifiers, in order from least specific to most specific. The default value is
|
||||
constructed from the environment as a combination of the <literal>spring.application.name</literal> and
|
||||
<literal>server.port</literal> (or <literal>spring.application.index</literal>, if set). The default value of the ID is
|
||||
constructed in the form of <literal>app:index:id</literal>, where:</simpara>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<simpara><literal>app</literal> is the <literal>vcap.application.name</literal> if it exists, or <literal>spring.application.name</literal></simpara>
|
||||
<simpara><literal>app</literal> is the <literal>vcap.application.name</literal>, if it exists, or <literal>spring.application.name</literal></simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<simpara><literal>index</literal> is the <literal>vcap.application.instance_index</literal> if it exists, or else <literal>spring.application.index</literal>, or else <literal>local.server.port</literal> (or <literal>server.port</literal> or <literal>0</literal>).</simpara>
|
||||
<simpara><literal>index</literal> is the <literal>vcap.application.instance_index</literal>, if it exists,
|
||||
<literal>spring.application.index</literal>, <literal>local.server.port</literal>, <literal>server.port</literal>, or <literal>0</literal> (in that order).</simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<simpara><literal>id</literal> is the <literal>vcap.application.instance_id</literal> if it exists, or else a random value.</simpara>
|
||||
<simpara><literal>id</literal> is the <literal>vcap.application.instance_id</literal>, if it exists, or a random value.</simpara>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<simpara>The HTTP endpoints accept a "destination" parameter, e.g. "/bus/refresh?destination=customers:9000", where the destination is a service ID. If the ID is owned by an instance on the Bus then it will process the message and all other instances will ignore it.</simpara>
|
||||
<simpara>The HTTP endpoints accept a “destination” parameter, such as
|
||||
<literal>/bus/refresh?destination=customers:9000</literal>, where <literal>destination</literal> is a service ID. If the ID
|
||||
is owned by an instance on the bus, it processes the message, and all other instances
|
||||
ignore it.</simpara>
|
||||
</chapter>
|
||||
<chapter xml:id="_addressing_all_instances_of_a_service">
|
||||
<title>Addressing all instances of a service</title>
|
||||
<simpara>The "destination" parameter is used in a Spring <literal>PathMatcher</literal> (with the path separator as a colon <literal>:</literal>) to determine if an instance will process the message. Using the example from above, "/bus/refresh?destination=customers:**" will target all instances of the "customers" service regardless of the rest of the service ID.</simpara>
|
||||
<title>Addressing All Instances of a Service</title>
|
||||
<simpara>The “destination” parameter is used in a Spring <literal>PathMatcher</literal> (with the path separator
|
||||
as a colon — <literal>:</literal>) to determine if an instance processes the message. Using the example
|
||||
from earlier, <literal>/bus/refresh?destination=customers:**</literal> targets all instances of the
|
||||
“customers” service regardless of the rest of the service ID.</simpara>
|
||||
</chapter>
|
||||
<chapter xml:id="_service_id_must_be_unique">
|
||||
<title>Service ID must be unique</title>
|
||||
<simpara>The bus tries to eliminate processing an event twice, once from the original <literal>ApplicationEvent</literal> and once from the queue. To do this, it checks the sending service ID againts the current service ID. If multiple instances of a service have the same ID, events will not be processed. Running on a local machine, each service will be on a different port and that will be part of the ID. Cloud Foundry supplies an index to differentiate. To ensure that the ID is unique outside Cloud Foundry, set <literal>spring.application.index</literal> to something unique for each instance of a service.</simpara>
|
||||
<title>Service ID Must Be Unique</title>
|
||||
<simpara>The bus tries twice to eliminate processing an event — once from the original
|
||||
<literal>ApplicationEvent</literal> and once from the queue. To do so, it checks the sending service ID
|
||||
against the current service ID. If multiple instances of a service have the same ID,
|
||||
events are not processed. When running on a local machine, each service is on a different
|
||||
port, and that port is part of the ID. Cloud Foundry supplies an index to differentiate.
|
||||
To ensure that the ID is unique outside Cloud Foundry, set <literal>spring.application.index</literal> to
|
||||
something unique for each instance of a service.</simpara>
|
||||
</chapter>
|
||||
<chapter xml:id="_customizing_the_message_broker">
|
||||
<title>Customizing the Message Broker</title>
|
||||
<simpara>Spring Cloud Bus uses
|
||||
<link xl:href="https://cloud.spring.io/spring-cloud-stream">Spring Cloud Stream</link> to
|
||||
broadcast the messages so to get messages to flow you only need to
|
||||
include the binder implementation of your choice in the
|
||||
classpath. There are convenient starters specifically for the bus with
|
||||
AMQP (RabbitMQ) and Kafka
|
||||
(<literal>spring-cloud-starter-bus-[amqp,kafka]</literal>). Generally speaking
|
||||
Spring Cloud Stream relies on Spring Boot autoconfiguration
|
||||
conventions for configuring middleware, so for instance the AMQP
|
||||
broker address can be changed with <literal>spring.rabbitmq.*</literal>
|
||||
configuration properties. Spring Cloud Bus has a handful of native
|
||||
configuration properties in <literal>spring.cloud.bus.*</literal>
|
||||
(e.g. <literal>spring.cloud.bus.destination</literal> is the name of the topic to use
|
||||
the the externall middleware). Normally the defaults will suffice.</simpara>
|
||||
<simpara>To lean more about how to customize the message broker settings
|
||||
consult the Spring Cloud Stream documentation.</simpara>
|
||||
<simpara>Spring Cloud Bus uses <link xl:href="https://cloud.spring.io/spring-cloud-stream">Spring Cloud Stream</link> to
|
||||
broadcast the messages. So, to get messages to flow, you need only include the binder
|
||||
implementation of your choice in the classpath. There are convenient starters for the bus
|
||||
with AMQP (RabbitMQ) and Kafka (<literal>spring-cloud-starter-bus-[amqp|kafka]</literal>). Generally
|
||||
speaking, Spring Cloud Stream relies on Spring Boot autoconfiguration conventions for
|
||||
configuring middleware. For instance, the AMQP broker address can be changed with
|
||||
<literal>spring.rabbitmq.*</literal> configuration properties. Spring Cloud Bus has a handful of
|
||||
native configuration properties in <literal>spring.cloud.bus.*</literal> (for example,
|
||||
<literal>spring.cloud.bus.destination</literal> is the name of the topic to use as the external
|
||||
middleware). Normally, the defaults suffice.</simpara>
|
||||
<simpara>To learn more about how to customize the message broker settings, consult the Spring Cloud
|
||||
Stream documentation.</simpara>
|
||||
</chapter>
|
||||
<chapter xml:id="_tracing_bus_events">
|
||||
<title>Tracing Bus Events</title>
|
||||
<simpara>Bus events (subclasses of <literal>RemoteApplicationEvent</literal>) can be traced by
|
||||
setting <literal>spring.cloud.bus.trace.enabled=true</literal>. If you do this then the
|
||||
Spring Boot <literal>TraceRepository</literal> (if it is present) will show each event
|
||||
sent and all the acks from each service instance. Example (from the
|
||||
<literal>/trace</literal> endpoint):</simpara>
|
||||
<simpara>Bus events (subclasses of <literal>RemoteApplicationEvent</literal>) can be traced by setting
|
||||
<literal>spring.cloud.bus.trace.enabled=true</literal>. If you do so, the Spring Boot <literal>TraceRepository</literal>
|
||||
(if it is present) shows each event sent and all the acks from each service instance. The
|
||||
following example comes from the <literal>/trace</literal> endpoint:</simpara>
|
||||
<programlisting language="json" linenumbering="unnumbered">{
|
||||
"timestamp": "2015-11-26T10:24:44.411+0000",
|
||||
"info": {
|
||||
@@ -112,42 +143,43 @@ sent and all the acks from each service instance. Example (from the
|
||||
"destination": "*:**"
|
||||
}
|
||||
}</programlisting>
|
||||
<simpara>This trace shows that a <literal>RefreshRemoteApplicationEvent</literal> was sent from
|
||||
<literal>customers:9000</literal>, broadcast to all services, and it was received
|
||||
(acked) by <literal>customers:9000</literal> and <literal>stores:8081</literal>.</simpara>
|
||||
<simpara>To handle the ack signals yourself you could add an <literal>@EventListener</literal>
|
||||
for the <literal>AckRemoteApplicationEvent</literal> and <literal>SentApplicationEvent</literal> types
|
||||
to your app (and enable tracing). Or you could tap into the
|
||||
<literal>TraceRepository</literal> and mine the data from there.</simpara>
|
||||
<simpara>The preceding trace shows that a <literal>RefreshRemoteApplicationEvent</literal> was sent from
|
||||
<literal>customers:9000</literal>, broadcast to all services, and received (acked) by <literal>customers:9000</literal> and
|
||||
<literal>stores:8081</literal>.</simpara>
|
||||
<simpara>To handle the ack signals yourself, you could add an <literal>@EventListener</literal> for the
|
||||
<literal>AckRemoteApplicationEvent</literal> and <literal>SentApplicationEvent</literal> types to your app (and enable
|
||||
tracing). Alternatively, you could tap into the <literal>TraceRepository</literal> and mine the data from
|
||||
there.</simpara>
|
||||
<note>
|
||||
<simpara>Any Bus application can trace acks, but sometimes it will be
|
||||
<simpara>Any Bus application can trace acks. However, sometimes, it is
|
||||
useful to do this in a central service that can do more complex
|
||||
queries on the data. Or forward it to a specialized tracing service.</simpara>
|
||||
queries on the data or forward it to a specialized tracing service.</simpara>
|
||||
</note>
|
||||
</chapter>
|
||||
<chapter xml:id="_broadcasting_your_own_events">
|
||||
<title>Broadcasting Your Own Events</title>
|
||||
<simpara>The Bus can carry any event of type <literal>RemoteApplicationEvent</literal>, but the
|
||||
default transport is JSON and the deserializer needs to know which
|
||||
types are going to be used ahead of time. To register a new type it
|
||||
needs to be in a subpackage of <literal>org.springframework.cloud.bus.event</literal>.</simpara>
|
||||
<simpara>To customise the event name you can use <literal>@JsonTypeName</literal> on your custom class
|
||||
or rely on the default strategy which is to use the simple name of the class.
|
||||
Note that both the producer and the consumer will need access to the class
|
||||
definition.</simpara>
|
||||
<simpara>The Bus can carry any event of type <literal>RemoteApplicationEvent</literal>. The default transport is
|
||||
JSON, and the deserializer needs to know which types are going to be used ahead of time.
|
||||
To register a new type, you must put it in a subpackage of
|
||||
<literal>org.springframework.cloud.bus.event</literal>.</simpara>
|
||||
<simpara>To customise the event name, you can use <literal>@JsonTypeName</literal> on your custom class or rely on
|
||||
the default strategy, which is to use the simple name of the class.</simpara>
|
||||
<note>
|
||||
<simpara>Both the producer and the consumer need access to the class definition.</simpara>
|
||||
</note>
|
||||
<section xml:id="_registering_events_in_custom_packages">
|
||||
<title>Registering events in custom packages</title>
|
||||
<simpara>If you cannot or don’t want to use a subpackage of <literal>org.springframework.cloud.bus.event</literal>
|
||||
for your custom events, you must specify which packages to scan for events of
|
||||
type <literal>RemoteApplicationEvent</literal> using <literal>@RemoteApplicationEventScan</literal>. Packages
|
||||
<simpara>If you cannot or do not want to use a subpackage of <literal>org.springframework.cloud.bus.event</literal>
|
||||
for your custom events, you must specify which packages to scan for events of type
|
||||
<literal>RemoteApplicationEvent</literal> by using the <literal>@RemoteApplicationEventScan</literal> annotation. Packages
|
||||
specified with <literal>@RemoteApplicationEventScan</literal> include subpackages.</simpara>
|
||||
<simpara>For example, if you have a custom event called <literal>FooEvent</literal>:</simpara>
|
||||
<simpara>For example, consider the following custom event, called <literal>MyEvent</literal>:</simpara>
|
||||
<programlisting language="java" linenumbering="unnumbered">package com.acme;
|
||||
|
||||
public class FooEvent extends RemoteApplicationEvent {
|
||||
public class MyEvent extends RemoteApplicationEvent {
|
||||
...
|
||||
}</programlisting>
|
||||
<simpara>you can register this event with the deserializer in the following way:</simpara>
|
||||
<simpara>You can register that event with the deserializer in the following way:</simpara>
|
||||
<programlisting language="java" linenumbering="unnumbered">package com.acme;
|
||||
|
||||
@Configuration
|
||||
@@ -156,10 +188,11 @@ public class BusConfiguration {
|
||||
...
|
||||
}</programlisting>
|
||||
<simpara>Without specifying a value, the package of the class where <literal>@RemoteApplicationEventScan</literal>
|
||||
is used will be registered. In this example <literal>com.acme</literal> will be registered using the
|
||||
package of <literal>BusConfiguration</literal>.</simpara>
|
||||
<simpara>You can also explicitly specify the packages to scan using the <literal>value</literal>, <literal>basePackages</literal> or
|
||||
<literal>basePackageClasses</literal> properties on <literal>@RemoteApplicationEventScan</literal>. For example:</simpara>
|
||||
is used is registered. In this example, <literal>com.acme</literal> is registered by using the package of
|
||||
<literal>BusConfiguration</literal>.</simpara>
|
||||
<simpara>You can also explicitly specify the packages to scan by using the <literal>value</literal>, <literal>basePackages</literal>
|
||||
or <literal>basePackageClasses</literal> properties on <literal>@RemoteApplicationEventScan</literal>, as shown in the
|
||||
following example:</simpara>
|
||||
<programlisting language="java" linenumbering="unnumbered">package com.acme;
|
||||
|
||||
@Configuration
|
||||
@@ -169,10 +202,12 @@ package of <literal>BusConfiguration</literal>.</simpara>
|
||||
public class BusConfiguration {
|
||||
...
|
||||
}</programlisting>
|
||||
<simpara>All examples of <literal>@RemoteApplicationEventScan</literal> above are equivalent,
|
||||
in that the <literal>com.acme</literal> package will be registered by explicitly specifying the
|
||||
packages on <literal>@RemoteApplicationEventScan</literal>. Note, you can specify multiple base
|
||||
packages to scan.</simpara>
|
||||
<simpara>All of the preceding examples of <literal>@RemoteApplicationEventScan</literal> are equivalent, in that the
|
||||
<literal>com.acme</literal> package is registered by explicitly specifying the packages on
|
||||
<literal>@RemoteApplicationEventScan</literal>.</simpara>
|
||||
<note>
|
||||
<simpara>You can specify multiple base packages to scan.</simpara>
|
||||
</note>
|
||||
</section>
|
||||
</chapter>
|
||||
</book>
|
||||
Reference in New Issue
Block a user