79 lines
17 KiB
HTML
79 lines
17 KiB
HTML
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Spring Boot Cloud CLI</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 Boot Cloud CLI</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="#_installation">1. Installation</a></span></dt><dt><span class="chapter"><a href="#_running_spring_cloud_services_in_development">2. Running Spring Cloud Services in Development</a></span></dt><dd><dl><dt><span class="section"><a href="#_adding_additional_applications">2.1. Adding Additional Applications</a></span></dt></dl></dd><dt><span class="chapter"><a href="#_writing_groovy_scripts_and_running_applications">3. Writing Groovy Scripts and Running Applications</a></span></dt><dt><span class="chapter"><a href="#_encryption_and_decryption">4. Encryption and Decryption</a></span></dt></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 Boot CLI provides <a class="link" href="http://projects.spring.io/spring-boot" target="_top">Spring
|
|
Boot</a> command line features for <a class="link" href="https://github.com/spring-cloud" target="_top">Spring
|
|
Cloud</a>. You can write Groovy scripts to run Spring Cloud component
|
|
applications (e.g. <code class="literal">@EnableEurekaServer</code>). You can also easily do
|
|
things like encryption and decryption to support Spring Cloud Config
|
|
clients with secret configuration values. With the Launcher CLI you
|
|
can launch services like Eureka, Zipkin, Config Server
|
|
conveniently all at once from the command line (very useful at
|
|
development time).</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-cli/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="_installation" href="#_installation"></a>1. Installation</h1></div></div></div><p>To install, make
|
|
sure you have
|
|
<a class="link" href="https://github.com/spring-projects/spring-boot" target="_top">Spring Boot CLI</a>
|
|
(1.5.2 or better):</p><pre class="literallayout">$ spring version
|
|
Spring CLI v1.5.4.RELEASE</pre><p>E.g. for SDKMan users</p><pre class="screen">$ sdk install springboot 1.5.4.RELEASE
|
|
$ sdk use springboot 1.5.4.RELEASE</pre><p>and install the Spring Cloud plugin</p><pre class="screen">$ mvn install
|
|
$ spring install org.springframework.cloud:spring-cloud-cli:1.4.0.BUILD-SNAPSHOT</pre><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Important"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="images/important.png"></td><th align="left">Important</th></tr><tr><td align="left" valign="top"><p><span class="strong"><strong>Prerequisites:</strong></span> to use the encryption and decryption features
|
|
you need the full-strength JCE installed in your JVM (it’s not there by default).
|
|
You can download the "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files"
|
|
from Oracle, and follow instructions for installation (essentially replace the 2 policy files
|
|
in the JRE lib/security directory with the ones that you downloaded).</p></td></tr></table></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_running_spring_cloud_services_in_development" href="#_running_spring_cloud_services_in_development"></a>2. Running Spring Cloud Services in Development</h1></div></div></div><p>The Launcher CLI can be used to run common services like Eureka,
|
|
Config Server etc. from the command line. To list the available
|
|
services you can do <code class="literal">spring cloud --list</code>, and to launch a default set
|
|
of services just <code class="literal">spring cloud</code>. To choose the services to deploy,
|
|
just list them on the command line, e.g.</p><pre class="screen">$ spring cloud eureka configserver h2 kafka stubrunner zipkin</pre><p>Summary of supported deployables:</p><div class="informaltable"><table style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; "><colgroup><col class="col_1"><col class="col_2"><col class="col_3"><col class="col_4"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">Service</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">Name</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">Address</th><th style="border-bottom: 0.5pt solid ; " align="left" valign="top">Description</th></tr></thead><tbody><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>eureka</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Eureka Server</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:8761" target="_top">http://localhost:8761</a></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Eureka server for service registration and discovery. All the other services show up in its catalog by default.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>configserver</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Config Server</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:8888" target="_top">http://localhost:8888</a></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Spring Cloud Config Server running in the "native" profile and serving configuration from the local directory ./launcher</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>h2</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>H2 Database</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:9095" target="_top">http://localhost:9095</a> (console), jdbc:h2:tcp://localhost:9096/{data}</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Relation database service. Use a file path for <code class="literal">{data}</code> (e.g. <code class="literal">./target/test</code>) when you connect. Remember that you can add <code class="literal">;MODE=MYSQL</code> or <code class="literal">;MODE=POSTGRESQL</code> to connect with compatibility to other server types.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>kafka</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Kafka Broker</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:9091" target="_top">http://localhost:9091</a> (actuator endpoints), localhost:9092</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"> </td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>hystrixdashboard</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Hystrix Dashboard</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:7979" target="_top">http://localhost:7979</a></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Any Spring Cloud app that declares Hystrix circuit breakers publishes metrics on <code class="literal">/hystrix.stream</code>. Type that address into the dashboard to visualize all the metrics,</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>dataflow</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Dataflow Server</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:9393" target="_top">http://localhost:9393</a></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Spring Cloud Dataflow server with UI at /admin-ui. Connect the Dataflow shell to target at root path.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>zipkin</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Zipkin Server</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:9411" target="_top">http://localhost:9411</a></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Zipkin Server with UI for visualizing traces. Stores span data in memory and accepts them via HTTP POST of JSON data.</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>stubrunner</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>Stub Runner Boot</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p><a class="link" href="http://localhost:8750" target="_top">http://localhost:8750</a></p></td><td style="" align="left" valign="top"><p>Downloads WireMock stubs, starts WireMock and feeds the started servers with stored stubs. Pass <code class="literal">stubrunner.ids</code> to pass stub coordinates and then go to <code class="literal"><a class="link" href="http://localhost:8750/stubs" target="_top">http://localhost:8750/stubs</a></code>.</p></td></tr></tbody></table></div><p>Each of these apps can be configured using a local YAML file with the same name (in the current
|
|
working directory or a subdirectory called "config" or in <code class="literal">~/.spring-cloud</code>). E.g. in <code class="literal">configserver.yml</code> you might want to
|
|
do something like this to locate a local git repository for the backend:</p><p><b>configserver.yml. </b>
|
|
</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">spring</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> profiles</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> active</span>: git
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> cloud</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> config</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> server</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> git</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> uri</span>: file://${user.home}/dev/demo/config-repo</pre><p>
|
|
</p><p>E.g. in Stub Runner app you could fetch stubs from your local <code class="literal">.m2</code> in the following way.</p><p><b>stubrunner.yml. </b>
|
|
</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">stubrunner</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> workOffline</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">true</span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> ids</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> - com.example</span>:beer-api-producer:+:<span class="hl-number">9876</span></pre><p>
|
|
</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_adding_additional_applications" href="#_adding_additional_applications"></a>2.1 Adding Additional Applications</h2></div></div></div><p>Additional applications can be added to <code class="literal">./config/cloud.yml</code> (not
|
|
<code class="literal">./config.yml</code> because that would replace the defaults), e.g. with</p><p><b>config/cloud.yml. </b>
|
|
</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">spring</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> cloud</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> launcher</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> deployables</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> source</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> coordinates</span>: maven://com.example:source:<span class="hl-number">0.0</span>.<span class="hl-number">1</span>-SNAPSHOT
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> port</span>: <span class="hl-number">7000</span>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> sink</span>:
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> coordinates</span>: maven://com.example:sink:<span class="hl-number">0.0</span>.<span class="hl-number">1</span>-SNAPSHOT
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"> port</span>: <span class="hl-number">7001</span></pre><p>
|
|
</p><p>when you list the apps:</p><pre class="screen">$ spring cloud --list
|
|
source sink configserver dataflow eureka h2 hystrixdashboard kafka stubrunner zipkin</pre><p>(notice the additional apps at the start of the list).</p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_writing_groovy_scripts_and_running_applications" href="#_writing_groovy_scripts_and_running_applications"></a>3. Writing Groovy Scripts and Running Applications</h1></div></div></div><p>Spring Cloud CLI has support for most of the Spring Cloud declarative
|
|
features, such as the <code class="literal">@Enable*</code> class of annotations. For example,
|
|
here is a fully functional Eureka server</p><p><b>app.groovy. </b>
|
|
</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@EnableEurekaServer</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> Eureka {}</pre><p>
|
|
</p><p>which you can run from the command line like this</p><pre class="screen">$ spring run app.groovy</pre><p>To include additional dependencies, often it suffices just to add the
|
|
appropriate feature-enabling annotation, e.g. <code class="literal">@EnableConfigServer</code>,
|
|
<code class="literal">@EnableOAuth2Sso</code> or <code class="literal">@EnableEurekaClient</code>. To manually include a
|
|
dependency you can use a <code class="literal">@Grab</code> with the special "Spring Boot" short
|
|
style artifact co-ordinates, i.e. with just the artifact ID (no need
|
|
for group or version information), e.g. to set up a client app to
|
|
listen on AMQP for management events from the Spring CLoud Bus:</p><p><b>app.groovy. </b>
|
|
</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Grab('spring-cloud-starter-bus-amqp')</span></em>
|
|
<em><span class="hl-annotation" style="color: gray">@RestController</span></em>
|
|
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> Service {
|
|
<em><span class="hl-annotation" style="color: gray">@RequestMapping('/')</span></em>
|
|
def home() { [message: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">'Hello'</span>] }
|
|
}</pre><p>
|
|
</p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_encryption_and_decryption" href="#_encryption_and_decryption"></a>4. Encryption and Decryption</h1></div></div></div><p>The Spring Cloud CLI comes with an "encrypt" and a "decrypt"
|
|
command. Both accept arguments in the same form with a key specified
|
|
as a mandatory "--key", e.g.</p><pre class="screen">$ spring encrypt mysecret --key foo
|
|
682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda
|
|
$ spring decrypt --key foo 682bc583f4641835fa2db009355293665d2647dade3375c0ee201de2a49f7bda
|
|
mysecret</pre><p>To use a key in a file (e.g. an RSA public key for encyption) prepend
|
|
the key value with "@" and provide the file path, e.g.</p><pre class="screen">$ spring encrypt mysecret --key @${HOME}/.ssh/id_rsa.pub
|
|
AQAjPgt3eFZQXwt8tsHAVv/QHiY5sI2dRcR+...</pre></div></div></body></html> |