Sync docs from v2.0.0.RELEASE to gh-pages
35
spring-cloud-aws/2.0.0.RELEASE/css/highlight.css
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
code highlight CSS resemblign the Eclipse IDE default color schema
|
||||
@author Costin Leau
|
||||
*/
|
||||
|
||||
.hl-keyword {
|
||||
color: #7F0055;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hl-comment {
|
||||
color: #3F5F5F;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-multiline-comment {
|
||||
color: #3F5FBF;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-tag {
|
||||
color: #3F7F7F;
|
||||
}
|
||||
|
||||
.hl-attribute {
|
||||
color: #7F007F;
|
||||
}
|
||||
|
||||
.hl-value {
|
||||
color: #2A00FF;
|
||||
}
|
||||
|
||||
.hl-string {
|
||||
color: #2A00FF;
|
||||
}
|
||||
9
spring-cloud-aws/2.0.0.RELEASE/css/manual-multipage.css
Normal file
@@ -0,0 +1,9 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body.firstpage {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: none;
|
||||
}
|
||||
6
spring-cloud-aws/2.0.0.RELEASE/css/manual-singlepage.css
Normal file
@@ -0,0 +1,6 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
344
spring-cloud-aws/2.0.0.RELEASE/css/manual.css
Normal file
@@ -0,0 +1,344 @@
|
||||
@IMPORT url("highlight.css");
|
||||
|
||||
html {
|
||||
padding: 0pt;
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #333333;
|
||||
margin: 15px 30px;
|
||||
font-family: Helvetica, Arial, Freesans, Clean, Sans-serif;
|
||||
line-height: 1.6;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 16px;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
:not(a)>code {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
:not(pre)>code {
|
||||
background-color: #F2F2F2;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 4px;
|
||||
padding: 1px 3px 0;
|
||||
text-shadow: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
body>*:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
div {
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #CCCCCC;
|
||||
background: #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
color: #000000;
|
||||
cursor: text;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1,h2,h3 {
|
||||
margin: 40px 0 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 70px 0 30px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: 1px dotted #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h1 code {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h2,h2 code {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
h3,h3 code {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
h4,h1 code,h5,h5 code,h6,h6 code {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
div.book,div.chapter,div.appendix,div.part,div.preface {
|
||||
min-width: 300px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
p.releaseinfo {
|
||||
font-weight: bold;
|
||||
margin-bottom: 40px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
div.authorgroup {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
p.copyright {
|
||||
line-height: 1;
|
||||
margin-bottom: -5px;
|
||||
}
|
||||
|
||||
.legalnotice p {
|
||||
font-style: italic;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.titlepage+p,div.titlepage+p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1.0;
|
||||
color: black;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #4183C4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
ul,ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
li p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.table {
|
||||
margin: 1em;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.table table,div.informaltable table {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.table td {
|
||||
padding-left: 7px;
|
||||
padding-right: 7px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
line-height: 1.4;
|
||||
padding: 0 20px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
}
|
||||
|
||||
.sidebar p.title {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
pre.programlisting,pre.screen {
|
||||
font-size: 15px;
|
||||
padding: 6px 10px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
clear: both;
|
||||
overflow: auto;
|
||||
line-height: 1.4;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
border: 1px solid #DDDDDD !important;
|
||||
border-radius: 4px !important;
|
||||
border-collapse: separate !important;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
table thead {
|
||||
background: #F5F5F5;
|
||||
}
|
||||
|
||||
table tr {
|
||||
border: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
table th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
table th,table td {
|
||||
border: none !important;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
table tr:nth-child(2n) {
|
||||
background-color: #F8F8F8;
|
||||
}
|
||||
|
||||
td p {
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
div.table-contents td p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist *
|
||||
{
|
||||
border: none !important;
|
||||
background: none !important;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important p,div.note p,div.tip p,div.warning p {
|
||||
color: #6F6F6F;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
div.important code,div.note code,div.tip code,div.warning code {
|
||||
background-color: #F2F2F2 !important;
|
||||
border: 1px solid #CCCCCC !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 1px 3px 0 !important;
|
||||
text-shadow: none !important;
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.note th,.tip th,.warning th {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td
|
||||
{
|
||||
border-right: 1px solid #CCCCCC !important;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
div.calloutlist p,div.calloutlist td {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.calloutlist>table>tbody>tr>td:first-child {
|
||||
padding-left: 10px;
|
||||
width: 30px !important;
|
||||
}
|
||||
|
||||
div.important,div.note,div.tip,div.warning {
|
||||
margin-left: 0px !important;
|
||||
margin-right: 20px !important;
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
div.toc {
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
dl,dt {
|
||||
margin-top: 1px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.toc>dl>dt {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dt {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin: 20px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dd>dl>dt {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
margin: 10px 0 0 0;
|
||||
}
|
||||
|
||||
tbody.footnotes * {
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
div.footnote p {
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.footnote p sup {
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.navheader {
|
||||
border-bottom: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
div.navfooter {
|
||||
border-top: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-left: -1em;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.title>a {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
display: block;
|
||||
font-size: 0.85em;
|
||||
margin-top: 0.05em;
|
||||
margin-left: -1em;
|
||||
vertical-align: text-top;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.title>a:before {
|
||||
content: "\00A7";
|
||||
}
|
||||
|
||||
.title:hover>a,.title>a:hover,.title:hover>a:hover {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.title:focus>a,.title>a:focus,.title:focus>a:focus {
|
||||
outline: 0;
|
||||
}
|
||||
330
spring-cloud-aws/2.0.0.RELEASE/ghpages.sh
Normal file
@@ -0,0 +1,330 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
set -e
|
||||
|
||||
# Set default props like MAVEN_PATH, ROOT_FOLDER etc.
|
||||
function set_default_props() {
|
||||
# The script should be executed from the root folder
|
||||
ROOT_FOLDER=`pwd`
|
||||
echo "Current folder is ${ROOT_FOLDER}"
|
||||
|
||||
if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then
|
||||
echo "You're not in the root folder of the project!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prop that will let commit the changes
|
||||
COMMIT_CHANGES="no"
|
||||
MAVEN_PATH=${MAVEN_PATH:-}
|
||||
echo "Path to Maven is [${MAVEN_PATH}]"
|
||||
REPO_NAME=${PWD##*/}
|
||||
echo "Repo name is [${REPO_NAME}]"
|
||||
SPRING_CLOUD_STATIC_REPO=${SPRING_CLOUD_STATIC_REPO:-git@github.com:spring-cloud/spring-cloud-static.git}
|
||||
echo "Spring Cloud Static repo is [${SPRING_CLOUD_STATIC_REPO}"
|
||||
}
|
||||
|
||||
# Check if gh-pages exists and docs have been built
|
||||
function check_if_anything_to_sync() {
|
||||
git remote set-url --push origin `git config remote.origin.url | sed -e 's/^git:/https:/'`
|
||||
|
||||
if ! (git remote set-branches --add origin gh-pages && git fetch -q); then
|
||||
echo "No gh-pages, so not syncing"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ! [ -d docs/target/generated-docs ] && ! [ "${BUILD}" == "yes" ]; then
|
||||
echo "No gh-pages sources in docs/target/generated-docs, so not syncing"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
function retrieve_current_branch() {
|
||||
# Code getting the name of the current branch. For master we want to publish as we did until now
|
||||
# http://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch
|
||||
# If there is a branch already passed will reuse it - otherwise will try to find it
|
||||
CURRENT_BRANCH=${BRANCH}
|
||||
if [[ -z "${CURRENT_BRANCH}" ]] ; then
|
||||
CURRENT_BRANCH=$(git symbolic-ref -q HEAD)
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/}
|
||||
CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD}
|
||||
fi
|
||||
echo "Current branch is [${CURRENT_BRANCH}]"
|
||||
git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
}
|
||||
|
||||
# Switches to the provided value of the release version. We always prefix it with `v`
|
||||
function switch_to_tag() {
|
||||
git checkout v${VERSION}
|
||||
}
|
||||
|
||||
# Build the docs if switch is on
|
||||
function build_docs_if_applicable() {
|
||||
if [[ "${BUILD}" == "yes" ]] ; then
|
||||
./mvnw clean install -P docs -pl docs -DskipTests
|
||||
fi
|
||||
}
|
||||
|
||||
# Get the name of the `docs.main` property
|
||||
# Get whitelisted branches - assumes that a `docs` module is available under `docs` profile
|
||||
function retrieve_doc_properties() {
|
||||
MAIN_ADOC_VALUE=$("${MAVEN_PATH}"mvn -q \
|
||||
-Dexec.executable="echo" \
|
||||
-Dexec.args='${docs.main}' \
|
||||
--non-recursive \
|
||||
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
|
||||
echo "Extracted 'main.adoc' from Maven build [${MAIN_ADOC_VALUE}]"
|
||||
|
||||
|
||||
WHITELIST_PROPERTY=${WHITELIST_PROPERTY:-"docs.whitelisted.branches"}
|
||||
WHITELISTED_BRANCHES_VALUE=$("${MAVEN_PATH}"mvn -q \
|
||||
-Dexec.executable="echo" \
|
||||
-Dexec.args="\${${WHITELIST_PROPERTY}}" \
|
||||
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec \
|
||||
-P docs \
|
||||
-pl docs)
|
||||
echo "Extracted '${WHITELIST_PROPERTY}' from Maven build [${WHITELISTED_BRANCHES_VALUE}]"
|
||||
}
|
||||
|
||||
# Stash any outstanding changes
|
||||
function stash_changes() {
|
||||
git diff-index --quiet HEAD && dirty=$? || (echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1")
|
||||
if [ "$dirty" != "0" ]; then git stash; fi
|
||||
}
|
||||
|
||||
# Switch to gh-pages branch to sync it with current branch
|
||||
function add_docs_from_target() {
|
||||
local DESTINATION_REPO_FOLDER
|
||||
if [[ -z "${DESTINATION}" && -z "${CLONE}" ]] ; then
|
||||
DESTINATION_REPO_FOLDER=${ROOT_FOLDER}
|
||||
elif [[ "${CLONE}" == "yes" ]]; then
|
||||
mkdir -p ${ROOT_FOLDER}/target
|
||||
local clonedStatic=${ROOT_FOLDER}/target/spring-cloud-static
|
||||
if [[ ! -e "${clonedStatic}/.git" ]]; then
|
||||
echo "Cloning Spring Cloud Static to target"
|
||||
git clone ${SPRING_CLOUD_STATIC_REPO} ${clonedStatic} && git checkout gh-pages
|
||||
else
|
||||
echo "Spring Cloud Static already cloned - will pull changes"
|
||||
cd ${clonedStatic} && git checkout gh-pages && git pull origin gh-pages
|
||||
fi
|
||||
DESTINATION_REPO_FOLDER=${clonedStatic}/${REPO_NAME}
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
else
|
||||
if [[ ! -e "${DESTINATION}/.git" ]]; then
|
||||
echo "[${DESTINATION}] is not a git repository"
|
||||
exit 1
|
||||
fi
|
||||
DESTINATION_REPO_FOLDER=${DESTINATION}/${REPO_NAME}
|
||||
mkdir -p ${DESTINATION_REPO_FOLDER}
|
||||
echo "Destination was provided [${DESTINATION}]"
|
||||
fi
|
||||
cd ${DESTINATION_REPO_FOLDER}
|
||||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
|
||||
# Add git branches
|
||||
###################################################################
|
||||
if [[ -z "${VERSION}" ]] ; then
|
||||
copy_docs_for_current_version
|
||||
else
|
||||
copy_docs_for_provided_version
|
||||
fi
|
||||
commit_changes_if_applicable
|
||||
}
|
||||
|
||||
|
||||
# Copies the docs by using the retrieved properties from Maven build
|
||||
function copy_docs_for_current_version() {
|
||||
if [[ "${CURRENT_BRANCH}" == "master" ]] ; then
|
||||
echo -e "Current branch is master - will copy the current docs only to the root folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
# Not ignored...
|
||||
cp -rf $f ${ROOT_FOLDER}/
|
||||
git add -A ${ROOT_FOLDER}/$file
|
||||
fi
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
else
|
||||
echo -e "Current branch is [${CURRENT_BRANCH}]"
|
||||
# http://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin
|
||||
if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then
|
||||
mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
echo -e "Branch [${CURRENT_BRANCH}] is whitelisted! Will copy the current docs to the [${CURRENT_BRANCH}] folder"
|
||||
for f in docs/target/generated-docs/*; do
|
||||
file=${f#docs/target/generated-docs/*}
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ "${file}" == "${MAIN_ADOC_VALUE}.html" ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html
|
||||
else
|
||||
cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}
|
||||
git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/$file
|
||||
fi
|
||||
fi
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
else
|
||||
echo -e "Branch [${CURRENT_BRANCH}] is not on the white list! Check out the Maven [${WHITELIST_PROPERTY}] property in
|
||||
[docs] module available under [docs] profile. Won't commit any changes to gh-pages for this branch."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Copies the docs by using the explicitly provided version
|
||||
function copy_docs_for_provided_version() {
|
||||
local FOLDER=${DESTINATION_REPO_FOLDER}/${VERSION}
|
||||
mkdir -p ${FOLDER}
|
||||
echo -e "Current tag is [v${VERSION}] Will copy the current docs to the [${FOLDER}] folder"
|
||||
for f in ${ROOT_FOLDER}/docs/target/generated-docs/*; do
|
||||
file=${f#${ROOT_FOLDER}/docs/target/generated-docs/*}
|
||||
copy_docs_for_branch ${file} ${FOLDER}
|
||||
done
|
||||
COMMIT_CHANGES="yes"
|
||||
CURRENT_BRANCH="v${VERSION}"
|
||||
}
|
||||
|
||||
# Copies the docs from target to the provided destination
|
||||
# Params:
|
||||
# $1 - file from target
|
||||
# $2 - destination to which copy the files
|
||||
function copy_docs_for_branch() {
|
||||
local file=$1
|
||||
local destination=$2
|
||||
if ! git ls-files -i -o --exclude-standard --directory | grep -q ^${file}$; then
|
||||
# Not ignored...
|
||||
# We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html
|
||||
if [[ ("${file}" == "${MAIN_ADOC_VALUE}.html") || ("${file}" == "${REPO_NAME}.html") ]] ; then
|
||||
# We don't want to copy the spring-cloud-sleuth.html
|
||||
# we want it to be converted to index.html
|
||||
cp -rf $f ${destination}/index.html
|
||||
git add -A ${destination}/index.html
|
||||
else
|
||||
cp -rf $f ${destination}
|
||||
git add -A ${destination}/$file
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function commit_changes_if_applicable() {
|
||||
if [[ "${COMMIT_CHANGES}" == "yes" ]] ; then
|
||||
COMMIT_SUCCESSFUL="no"
|
||||
git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes"
|
||||
|
||||
# Uncomment the following push if you want to auto push to
|
||||
# the gh-pages branch whenever you commit to master locally.
|
||||
# This is a little extreme. Use with care!
|
||||
###################################################################
|
||||
if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then
|
||||
git push origin gh-pages
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Switch back to the previous branch and exit block
|
||||
function checkout_previous_branch() {
|
||||
# If -version was provided we need to come back to root project
|
||||
cd ${ROOT_FOLDER}
|
||||
git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script"
|
||||
if [ "$dirty" != "0" ]; then git stash pop; fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Assert if properties have been properly passed
|
||||
function assert_properties() {
|
||||
echo "VERSION [${VERSION}], DESTINATION [${DESTINATION}], CLONE [${CLONE}]"
|
||||
if [[ "${VERSION}" != "" && (-z "${DESTINATION}" && -z "${CLONE}") ]] ; then echo "Version was set but destination / clone was not!"; exit 1;fi
|
||||
if [[ ("${DESTINATION}" != "" && "${CLONE}" != "") && -z "${VERSION}" ]] ; then echo "Destination / clone was set but version was not!"; exit 1;fi
|
||||
if [[ "${DESTINATION}" != "" && "${CLONE}" == "yes" ]] ; then echo "Destination and clone was set. Pick one!"; exit 1;fi
|
||||
}
|
||||
|
||||
# Prints the usage
|
||||
function print_usage() {
|
||||
cat <<EOF
|
||||
The idea of this script is to update gh-pages branch with the generated docs. Without any options
|
||||
the script will work in the following manner:
|
||||
|
||||
- if there's no gh-pages / target for docs module then the script ends
|
||||
- for master branch the generated docs are copied to the root of gh-pages branch
|
||||
- for any other branch (if that branch is whitelisted) a subfolder with branch name is created
|
||||
and docs are copied there
|
||||
- if the version switch is passed (-v) then a tag with (v) prefix will be retrieved and a folder
|
||||
with that version number will be created in the gh-pages branch. WARNING! No whitelist verification will take place
|
||||
- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will
|
||||
switch to gh-pages of that repo and copy the generated docs to `docs/<project-name>/<version>`
|
||||
- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will
|
||||
switch to gh-pages of that repo and copy the generated docs to `docs/<project-name>/<version>`
|
||||
|
||||
USAGE:
|
||||
|
||||
You can use the following options:
|
||||
|
||||
-v|--version - the script will apply the whole procedure for a particular library version
|
||||
-d|--destination - the root of destination folder where the docs should be copied. You have to use the full path.
|
||||
E.g. point to spring-cloud-static folder. Can't be used with (-c)
|
||||
-b|--build - will run the standard build process after checking out the branch
|
||||
-c|--clone - will automatically clone the spring-cloud-static repo instead of providing the destination.
|
||||
Obviously can't be used with (-d)
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
# ==========================================
|
||||
# ____ ____ _____ _____ _____ _______
|
||||
# / ____|/ ____| __ \|_ _| __ \__ __|
|
||||
# | (___ | | | |__) | | | | |__) | | |
|
||||
# \___ \| | | _ / | | | ___/ | |
|
||||
# ____) | |____| | \ \ _| |_| | | |
|
||||
# |_____/ \_____|_| \_\_____|_| |_|
|
||||
#
|
||||
# ==========================================
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
case ${key} in
|
||||
-v|--version)
|
||||
VERSION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-d|--destination)
|
||||
DESTINATION="$2"
|
||||
shift # past argument
|
||||
;;
|
||||
-b|--build)
|
||||
BUILD="yes"
|
||||
;;
|
||||
-c|--clone)
|
||||
CLONE="yes"
|
||||
;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option: [$1]"
|
||||
print_usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift # past argument or value
|
||||
done
|
||||
|
||||
assert_properties
|
||||
set_default_props
|
||||
check_if_anything_to_sync
|
||||
if [[ -z "${VERSION}" ]] ; then
|
||||
retrieve_current_branch
|
||||
else
|
||||
switch_to_tag
|
||||
fi
|
||||
build_docs_if_applicable
|
||||
retrieve_doc_properties
|
||||
stash_changes
|
||||
add_docs_from_target
|
||||
checkout_previous_branch
|
||||
BIN
spring-cloud-aws/2.0.0.RELEASE/images/background.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/callouts/1.png
Normal file
|
After Width: | Height: | Size: 329 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/callouts/2.png
Normal file
|
After Width: | Height: | Size: 353 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/callouts/3.png
Normal file
|
After Width: | Height: | Size: 350 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/caution.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 216 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/graphics.graffle
Normal file
BIN
spring-cloud-aws/2.0.0.RELEASE/images/important.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/jdbc-retry-interceptor.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/logo.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/note.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/overview.png
Normal file
|
After Width: | Height: | Size: 313 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/sns-overview.png
Normal file
|
After Width: | Height: | Size: 131 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/tip.png
Normal file
|
After Width: | Height: | Size: 931 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/images/warning.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
117
spring-cloud-aws/2.0.0.RELEASE/index.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="generator" content="Asciidoctor 1.5.5">
|
||||
<title>spring-cloud-aws</title>
|
||||
<link rel="stylesheet" href="css/manual-singlepage.css">
|
||||
<style>
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.switch {
|
||||
border-width: 1px 1px 0 1px;
|
||||
border-style: solid;
|
||||
border-color: #7a2518;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.switch--item {
|
||||
padding: 10px;
|
||||
background-color: #ffffff;
|
||||
color: #7a2518;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch--item.selected {
|
||||
background-color: #7a2519;
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
function addBlockSwitches() {
|
||||
$('.primary').each(function() {
|
||||
primary = $(this);
|
||||
createSwitchItem(primary, createBlockSwitch(primary)).item.addClass("selected");
|
||||
primary.children('.title').remove();
|
||||
});
|
||||
$('.secondary').each(function(idx, node) {
|
||||
secondary = $(node);
|
||||
primary = findPrimary(secondary);
|
||||
switchItem = createSwitchItem(secondary, primary.children('.switch'));
|
||||
switchItem.content.addClass('hidden');
|
||||
findPrimary(secondary).append(switchItem.content);
|
||||
secondary.remove();
|
||||
});
|
||||
}
|
||||
|
||||
function createBlockSwitch(primary) {
|
||||
blockSwitch = $('<div class="switch"></div>');
|
||||
primary.prepend(blockSwitch);
|
||||
return blockSwitch;
|
||||
}
|
||||
|
||||
function findPrimary(secondary) {
|
||||
candidate = secondary.prev();
|
||||
while (!candidate.is('.primary')) {
|
||||
candidate = candidate.prev();
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
|
||||
function createSwitchItem(block, blockSwitch) {
|
||||
blockName = block.children('.title').text();
|
||||
content = block.children('.content').first().append(block.next('.colist'));
|
||||
item = $('<div class="switch--item">' + blockName + '</div>');
|
||||
item.on('click', '', content, function(e) {
|
||||
$(this).addClass('selected');
|
||||
$(this).siblings().removeClass('selected');
|
||||
e.data.siblings('.content').addClass('hidden');
|
||||
e.data.removeClass('hidden');
|
||||
});
|
||||
blockSwitch.append(item);
|
||||
return {'item': item, 'content': content};
|
||||
}
|
||||
|
||||
$(addBlockSwitches);
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body class="article">
|
||||
<div id="header">
|
||||
<h1>spring-cloud-aws</h1>
|
||||
</div>
|
||||
<div id="content">
|
||||
<div id="preamble">
|
||||
<div class="sectionbody">
|
||||
<div class="paragraph">
|
||||
<p>2.0.0.RELEASE</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect1">
|
||||
<h2 id="_pick_the_documentation_option">Pick The Documentation Option</h2>
|
||||
<div class="sectionbody">
|
||||
<div class="ulist">
|
||||
<ul>
|
||||
<li>
|
||||
<p><a href="single/spring-cloud-aws.html">Single HTML</a></p>
|
||||
</li>
|
||||
<li>
|
||||
<p><a href="multi/multi_spring-cloud-aws.html">Multi HTML</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/prettify/r298/prettify.min.js"></script>
|
||||
<script>prettyPrint()</script>
|
||||
</body>
|
||||
</html>
|
||||
35
spring-cloud-aws/2.0.0.RELEASE/multi/css/highlight.css
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
code highlight CSS resemblign the Eclipse IDE default color schema
|
||||
@author Costin Leau
|
||||
*/
|
||||
|
||||
.hl-keyword {
|
||||
color: #7F0055;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hl-comment {
|
||||
color: #3F5F5F;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-multiline-comment {
|
||||
color: #3F5FBF;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-tag {
|
||||
color: #3F7F7F;
|
||||
}
|
||||
|
||||
.hl-attribute {
|
||||
color: #7F007F;
|
||||
}
|
||||
|
||||
.hl-value {
|
||||
color: #2A00FF;
|
||||
}
|
||||
|
||||
.hl-string {
|
||||
color: #2A00FF;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body.firstpage {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: none;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
344
spring-cloud-aws/2.0.0.RELEASE/multi/css/manual.css
Normal file
@@ -0,0 +1,344 @@
|
||||
@IMPORT url("highlight.css");
|
||||
|
||||
html {
|
||||
padding: 0pt;
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #333333;
|
||||
margin: 15px 30px;
|
||||
font-family: Helvetica, Arial, Freesans, Clean, Sans-serif;
|
||||
line-height: 1.6;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 16px;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
:not(a)>code {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
:not(pre)>code {
|
||||
background-color: #F2F2F2;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 4px;
|
||||
padding: 1px 3px 0;
|
||||
text-shadow: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
body>*:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
div {
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #CCCCCC;
|
||||
background: #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
color: #000000;
|
||||
cursor: text;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1,h2,h3 {
|
||||
margin: 40px 0 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 70px 0 30px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: 1px dotted #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h1 code {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h2,h2 code {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
h3,h3 code {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
h4,h1 code,h5,h5 code,h6,h6 code {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
div.book,div.chapter,div.appendix,div.part,div.preface {
|
||||
min-width: 300px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
p.releaseinfo {
|
||||
font-weight: bold;
|
||||
margin-bottom: 40px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
div.authorgroup {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
p.copyright {
|
||||
line-height: 1;
|
||||
margin-bottom: -5px;
|
||||
}
|
||||
|
||||
.legalnotice p {
|
||||
font-style: italic;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.titlepage+p,div.titlepage+p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1.0;
|
||||
color: black;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #4183C4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
ul,ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
li p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.table {
|
||||
margin: 1em;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.table table,div.informaltable table {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.table td {
|
||||
padding-left: 7px;
|
||||
padding-right: 7px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
line-height: 1.4;
|
||||
padding: 0 20px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
}
|
||||
|
||||
.sidebar p.title {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
pre.programlisting,pre.screen {
|
||||
font-size: 15px;
|
||||
padding: 6px 10px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
clear: both;
|
||||
overflow: auto;
|
||||
line-height: 1.4;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
border: 1px solid #DDDDDD !important;
|
||||
border-radius: 4px !important;
|
||||
border-collapse: separate !important;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
table thead {
|
||||
background: #F5F5F5;
|
||||
}
|
||||
|
||||
table tr {
|
||||
border: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
table th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
table th,table td {
|
||||
border: none !important;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
table tr:nth-child(2n) {
|
||||
background-color: #F8F8F8;
|
||||
}
|
||||
|
||||
td p {
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
div.table-contents td p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist *
|
||||
{
|
||||
border: none !important;
|
||||
background: none !important;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important p,div.note p,div.tip p,div.warning p {
|
||||
color: #6F6F6F;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
div.important code,div.note code,div.tip code,div.warning code {
|
||||
background-color: #F2F2F2 !important;
|
||||
border: 1px solid #CCCCCC !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 1px 3px 0 !important;
|
||||
text-shadow: none !important;
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.note th,.tip th,.warning th {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td
|
||||
{
|
||||
border-right: 1px solid #CCCCCC !important;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
div.calloutlist p,div.calloutlist td {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.calloutlist>table>tbody>tr>td:first-child {
|
||||
padding-left: 10px;
|
||||
width: 30px !important;
|
||||
}
|
||||
|
||||
div.important,div.note,div.tip,div.warning {
|
||||
margin-left: 0px !important;
|
||||
margin-right: 20px !important;
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
div.toc {
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
dl,dt {
|
||||
margin-top: 1px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.toc>dl>dt {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dt {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin: 20px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dd>dl>dt {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
margin: 10px 0 0 0;
|
||||
}
|
||||
|
||||
tbody.footnotes * {
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
div.footnote p {
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.footnote p sup {
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.navheader {
|
||||
border-bottom: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
div.navfooter {
|
||||
border-top: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-left: -1em;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.title>a {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
display: block;
|
||||
font-size: 0.85em;
|
||||
margin-top: 0.05em;
|
||||
margin-left: -1em;
|
||||
vertical-align: text-top;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.title>a:before {
|
||||
content: "\00A7";
|
||||
}
|
||||
|
||||
.title:hover>a,.title>a:hover,.title:hover>a:hover {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.title:focus>a,.title>a:focus,.title:focus>a:focus {
|
||||
outline: 0;
|
||||
}
|
||||
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/background.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/callouts/1.png
Normal file
|
After Width: | Height: | Size: 329 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/callouts/2.png
Normal file
|
After Width: | Height: | Size: 353 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/callouts/3.png
Normal file
|
After Width: | Height: | Size: 350 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/caution.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/important.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/logo.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/note.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/tip.png
Normal file
|
After Width: | Height: | Size: 931 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/multi/images/warning.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
103
spring-cloud-aws/2.0.0.RELEASE/multi/multi__basic_setup.html
Normal file
@@ -0,0 +1,103 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>2. Basic setup</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__using_amazon_web_services.html" title="1. Using Amazon Web Services"><link rel="next" href="multi__cloud_environment.html" title="3. Cloud environment"></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. Basic setup</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__using_amazon_web_services.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__cloud_environment.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_basic_setup" href="#_basic_setup"></a>2. Basic setup</h1></div></div></div><p>Before using the Spring Cloud AWS module developers have to pick the dependencies and configure the Spring Cloud AWS module.
|
||||
The next chapters describe the dependency management and also the basic configuration for the Spring AWS Cloud project.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_spring_cloud_aws_maven_dependency_management" href="#_spring_cloud_aws_maven_dependency_management"></a>2.1 Spring Cloud AWS maven dependency management</h2></div></div></div><p>Spring Cloud AWS module dependencies can be used directly in <a class="link" href="http://maven.apache.org" target="_top">Maven</a> with a direct configuration
|
||||
of the particular module. The Spring Cloud AWS module includes all transitive dependencies for the Spring modules and
|
||||
also the Amazon SDK that are needed to operate the modules. The general dependency configuration will look like this:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependencies></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-aws-context<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>{spring-cloud-version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependencies></span></pre><p>Different modules can be included by replacing the module name with the respective one (e.g. <code class="literal">spring-cloud-aws-messaging</code>
|
||||
instead of <code class="literal">spring-cloud-aws-context</code>)</p><p>The example above works with the Maven Central repository. To use the Spring Maven repository (e.g. for milestones or
|
||||
developer snapshots), you need to specify the repository location in your Maven configuration. For full releases:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repositories></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repository></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>io.spring.repo.maven.release<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>http://repo.spring.io/release/<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repository></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repositories></span></pre><p>For milestones:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repositories></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><repository></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><id></span>io.spring.repo.maven.milestone<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></id></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><url></span>http://repo.spring.io/milestone/<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></url></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><snapshots></span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><enabled></span>false<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></enabled></span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></snapshots></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repository></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></repositories></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_amazon_sdk_configuration" href="#_amazon_sdk_configuration"></a>2.2 Amazon SDK configuration</h2></div></div></div><p>The Spring Cloud AWS configuration is currently done using custom elements provided by Spring Cloud AWS namespaces.
|
||||
JavaConfig will be supported soon. The configuration setup is done directly in Spring XML configuration files
|
||||
so that the elements can be directly used. Each module of Spring Cloud AWS provides custom namespaces to allow the modular
|
||||
use of the modules. A typical XML configuration to use Spring Cloud AWS is outlined below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:xsi</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-context</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cloud/aws/context
|
||||
http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"..."</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sdk_credentials_configuration" href="#_sdk_credentials_configuration"></a>2.2.1 SDK credentials configuration</h3></div></div></div><p>In order to make calls to the Amazon Web Service the credentials must be configured for the the Amazon SDK. Spring Cloud AWS
|
||||
provides support to configure an application context specific credentials that are used for <span class="emphasis"><em>each</em></span> service call for requests done
|
||||
by Spring Cloud AWS components, with the exception of the Parameter Store Configuration.
|
||||
Therefore there must be <span class="strong"><strong>exactly one</strong></span> configuration of the credentials for an entire application context.</p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>The <code class="literal">com.amazonaws.auth.DefaultAWSCredentialsProviderChain</code> is used by all the clients if there is no dedicated credentials
|
||||
provider defined. This will essentially use the following authentication information</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">use the environment variables <code class="literal">AWS_ACCESS_KEY_ID</code> and <code class="literal">AWS_SECRET_ACCESS_KEY</code></li><li class="listitem">use the system properties <code class="literal">aws.accessKeyId</code> and <code class="literal">aws.secretKey</code></li><li class="listitem">use the user specific profile credentials file</li><li class="listitem">use ECS credentials if the <code class="literal">AWS_CONTAINER_CREDENTIALS_RELATIVE_URI</code> environment variable is set</li><li class="listitem">use the instance profile credentials (see below)</li></ul></div></td></tr></table></div><p>Based on the overall credentials policy there are different options to configure the credentials. The possible ones are described in
|
||||
the following sub-chapters.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_simple_credentials_configuration" href="#_simple_credentials_configuration"></a>Simple credentials configuration</h4></div></div></div><p>Credentials for the Amazon SDK consist of an access key (which might be shared) and a secret key (which must <span class="strong"><strong>not</strong></span> be shared). Both
|
||||
security attributes can be configured using the XML namespaces for each Amazon SDK service created by the Spring Cloud AWS
|
||||
module. The overall configuration looks like this</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:simple-credentials</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">access-key</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"AKIAIO"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">secret-key</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"wJalrXUtnFEMI/K7M"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left">Caution</th></tr><tr><td align="left" valign="top"><p>The access-key and secret-key should be externalized into property files (e.g. Spring Boot application configuration)
|
||||
and not be checked in into the source management system.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_instance_profile_configuration" href="#_instance_profile_configuration"></a>Instance profile configuration</h4></div></div></div><p>An <a class="link" href="http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html" target="_top">instance profile configuration</a> allows to assign
|
||||
a profile that is authorized by a role while starting an EC2 instance. All calls made from the EC2 instance are then authenticated
|
||||
with the instance profile specific user role. Therefore there is no dedicated access-key and secret-key needed in the configuration.
|
||||
The configuration for the instance profile in Spring Cloud AWS looks like this:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:instance-profile-credentials/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"></aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_mixing_both_security_configurations" href="#_mixing_both_security_configurations"></a>Mixing both security configurations</h4></div></div></div><p>In some cases it is useful to combine both authentication strategies to allow the application to use the instance profile
|
||||
with a fallback for an explicit access-key and secret-key configuration. This is useful if the application is tested inside
|
||||
EC2 (e.g. on a test server) and locally for testing. The next snippet shows a combination of both security configurations.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:instance-profile-credentials/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:simple-credentials</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">access-key</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${accessKey:}"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">secret-key</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${secretKey:}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>The access-key and secret-key are defined using a placeholder expressions along with a default value to avoid bootstrap
|
||||
errors if the properties are not configured at all.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_parameter_store_configuration_credentials_and_region_configuration" href="#_parameter_store_configuration_credentials_and_region_configuration"></a>Parameter Store Configuration credentials and region configuration</h4></div></div></div><p>The Parameter Store Configuration support uses a bootstrap context to configure a default <code class="literal">AWSSimpleSystemsManagement</code>
|
||||
client, which uses a <code class="literal">com.amazonaws.auth.DefaultAWSCredentialsProviderChain</code> and <code class="literal">com.amazonaws.regions.DefaultAwsRegionProviderChain</code>.
|
||||
If you want to override this, then you need to
|
||||
<a class="link" href="http://cloud.spring.io/spring-cloud-static/Edgware.SR2/multi/multi__spring_cloud_context_application_context_services.html#_customizing_the_bootstrap_configuration" target="_top">define your own Spring Cloud bootstrap configuration class</a>
|
||||
with a bean of type <code class="literal">AWSSimpleSystemsManagement</code> that’s configured to use your chosen credentials and/or region provider.
|
||||
Because this context is created when your Spring Cloud Bootstrap context is created, you can’t simply override the bean
|
||||
in a regular <code class="literal">@Configuration</code> class.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_region_configuration" href="#_region_configuration"></a>2.2.2 Region configuration</h3></div></div></div><p>Amazon Web services are available in different <a class="link" href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html" target="_top">regions</a>. Based
|
||||
on the custom requirements, the user can host the application on different Amazon regions. The <code class="literal">spring-cloud-aws-context</code>
|
||||
module provides a way to define the region for the entire application context.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_explicit_region_configuration" href="#_explicit_region_configuration"></a>Explicit region configuration</h4></div></div></div><p>The region can be explicitly configured using an XML element. This is particularly useful if the region can not be automatically
|
||||
derived because the application is not hosted on a EC2 instance (e.g. local testing) or the region must be manually overridden.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-west-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>It is also allowed to use expressions or placeholders to externalize the configuration and ensure that the region can
|
||||
be reconfigured with property files or system properties.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_automatic_region_configuration" href="#_automatic_region_configuration"></a>Automatic region configuration</h4></div></div></div><p>If the application context is started inside an EC2 instance, then the region can automatically be fetched from the
|
||||
<a class="link" href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html" target="_top">instance metadata</a> and therefore must
|
||||
not be configured statically. The configuration will look like this:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">auto-detect</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"true"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_service_specific_region_configuration" href="#_service_specific_region_configuration"></a>Service specific region configuration</h4></div></div></div><p>A region can also be overridden for particular services if one application context consumes services from different regions.
|
||||
The configuration can be done globally like described above and configured for each service with a region attribute.
|
||||
The configuration might look like this for a database service (described later)</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-central-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-west-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><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>While it is theoretically possible to use multiple regions per application, we strongly recommend to write applications that
|
||||
are hosted only inside one region and split the application if it is hosted in different regions at the same time.</p></td></tr></table></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_spring_boot_auto_configuration" href="#_spring_boot_auto_configuration"></a>2.2.3 Spring Boot auto-configuration</h3></div></div></div><p>Following the Spring Cloud umbrella project, Spring Cloud AWS also provides dedicated Spring Boot support. Spring Cloud
|
||||
AWS can be configured using Spring Boot properties and will also automatically guess any sensible configuration based on
|
||||
the general setup.</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_maven_dependencies" href="#_maven_dependencies"></a>Maven dependencies</h4></div></div></div><p>Spring Cloud AWS provides a dedicated module to enable the Spring Boot support. That module must be added to the general
|
||||
maven dependency inside the application. The typical configuration will look like this</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependencies></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-aws-autoconfigure<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>{spring-cloud-version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependencies></span></pre><p>Additional dependencies to enable particular features like messaging and JDBC have to be added. Spring Cloud AWS will
|
||||
only configure classes that are available in the Spring Boot application’s classpath.</p></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_configuring_credentials" href="#_configuring_credentials"></a>Configuring credentials</h4></div></div></div><p>Spring Boot provides a standard way to define properties with property file or YAML configuration files. Spring Cloud
|
||||
AWS provides support to configure the credential information with the Spring Boot application configuration files.
|
||||
Spring Cloud AWS provides the following properties to configure the credentials setup for the whole application.</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">property</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">example</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>cloud.aws.credentials.accessKey</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>AKIAIOSFODNN7EXAMPLE</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The access key to be used with a static provider</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.credentials.secretKey</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The secret key to be used with a static provider</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.credentials.instanceProfile</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>true</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Configures an instance profile credentials provider with no further configuration</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.credentials.useDefaultAwsCredentialsChain</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>true</p></td><td style="" align="left" valign="top"><p>Use the DefaultAWSCredentials Chain instead of configuring a custom credentials chain</p></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_configuring_region" href="#_configuring_region"></a>Configuring region</h4></div></div></div><p>Like for the credentials, the Spring Cloud AWS module also supports the configuration of the region inside the Spring
|
||||
Boot configuration files. The region can be automatically detected or explicitly configured (e.g. in case of local tests
|
||||
against the AWS cloud).</p><p>The properties to configure the region are shown below</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">property</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">example</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>cloud.aws.region.auto</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>true</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Enables automatic region detection based on the EC2 meta data service</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.region.static</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>eu-west-1</p></td><td style="" align="left" valign="top"><p>Configures a static region for the application. Possible regions are (currently) us-east-1, us-west-1, us-west-2,
|
||||
eu-west-1, eu-central-1, ap-southeast-1, ap-southeast-1, ap-northeast-1, sa-east-1, cn-north-1 and any custom region
|
||||
configured with own region meta data</p></td></tr></tbody></table></div></div></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__using_amazon_web_services.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__cloud_environment.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">1. Using Amazon Web Services </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 3. Cloud environment</td></tr></table></div></body></html>
|
||||
99
spring-cloud-aws/2.0.0.RELEASE/multi/multi__caching.html
Normal file
@@ -0,0 +1,99 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>6. Caching</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__messaging.html" title="5. Messaging"><link rel="next" href="multi__data_access_with_jdbc.html" title="7. Data Access with JDBC"></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. Caching</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__messaging.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__data_access_with_jdbc.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_caching" href="#_caching"></a>6. Caching</h1></div></div></div><p>Caching in a cloud environment is useful for applications to reduce the latency and to save database round trips.
|
||||
Reducing database round trips can significantly reduce the requirements for the database instance. The Spring Framework
|
||||
provides, since version 3.1, a unified Cache abstraction to allow declarative caching in applications analogous to the
|
||||
declarative transactions.</p><p>Spring Cloud AWS integrates the <a class="link" href="http://aws.amazon.com/elasticache/" target="_top">Amazon ElastiCache</a> service into the Spring unified
|
||||
caching abstraction providing a cache manager based on the memcached and Redis protocols. The caching support for Spring
|
||||
Cloud AWS provides its own memcached implementation for ElastiCache and uses
|
||||
<a class="link" href="http://projects.spring.io/spring-data-redis/" target="_top">Spring Data Redis</a> for Redis caches.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_dependencies_for_redis_caches" href="#_configuring_dependencies_for_redis_caches"></a>6.1 Configuring dependencies for Redis caches</h2></div></div></div><p>Spring Cloud AWS delivers its own implementation of a memcached cache, therefore no other dependencies are needed. For Redis
|
||||
Spring Cloud AWS relies on Spring Data Redis to support caching and also to allow multiple Redis drivers to be used. Spring
|
||||
Cloud AWS supports all Redis drivers that Spring Data Redis supports (currently Jedis, JRedis, SRP and Lettuce) with Jedis
|
||||
being used internally for testing against ElastiCache. A dependency definition for Redis with Jedis is shown in the example</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependencies></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.data<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-data-redis<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>${spring-data-redis.version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>redis.clients<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>jedis<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>2.6.1<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependencies></span></pre><p>Spring Cloud AWS will automatically detect the Redis driver and will use one of them automatically.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_caching_with_xml" href="#_configuring_caching_with_xml"></a>6.2 Configuring caching with XML</h2></div></div></div><p>The cache support for Spring Cloud AWS resides in the context module and can therefore be used if the context module
|
||||
is already imported in the project. The cache integration provides its own namespace to configure cache clusters that are
|
||||
hosted in the Amazon ElastiCache service. The next example contains a configuration for the cache cluster and the Spring
|
||||
configuration to enable declarative, annotation-based caching.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-cache</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/cache"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:cache</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cache"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/cache
|
||||
http://www.springframework.org/schema/cloud/aws/cache/spring-cloud-aws-cache.xsd
|
||||
http://www.springframework.org/schema/cache
|
||||
http://www.springframework.org/schema/cache/spring-cache.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-cluster</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"CacheCluster"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-cache:cache-manager></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><cache:annotation-driven /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>The configuration above configures a <code class="literal">cache-manager</code> with one cache with the name <code class="literal">CacheCluster</code> that represents an
|
||||
<a class="link" href="http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/ManagingCacheClusters.html" target="_top">ElasticCache cluster</a>.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_mixing_caches" href="#_mixing_caches"></a>6.2.1 Mixing caches</h3></div></div></div><p>Applications may have the need for multiple caches that are maintained by one central cache cluster. The Spring Cloud
|
||||
AWS caching support allows to define multiple caches inside one cache manager and also to use externally defined caches
|
||||
inside the cache manager.</p><p>The example below demonstrates a configuration example that contains a pre-configured cache with a <code class="literal">cache-ref</code> element
|
||||
(which might be a local cache) and a <code class="literal">cache-cluster</code> configuration for ElastiCache cache clusters.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-cache:cache-manager</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"cacheManager"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-ref</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">ref</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"memcached"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-cluster</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"SimpleCache"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_defining_expiration" href="#_defining_expiration"></a>6.2.2 Defining expiration</h3></div></div></div><p>The Spring cache demarcation does not support expiry time configuration and leaves it up to the cache implementation
|
||||
to support an expiry time. The Spring Cloud AWS cache configuration supports the expiry time setting per cache. The
|
||||
expiry time will be passed to the memcached service.</p><p>The <code class="literal">cache-cluster</code> element accepts an expiration attribute that defines the expiration time in seconds.
|
||||
No configured values implies that there is an infinite expiration time.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-cluster</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">expiration</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"10000"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"CacheCluster"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_caching_using_java_configuration" href="#_configuring_caching_using_java_configuration"></a>6.3 Configuring caching using Java configuration</h2></div></div></div><p>Spring Cloud AWS also support the cache configuration with Java configuration classes. On any <code class="literal">Configuration</code> class,
|
||||
the caching can be configured using the <code class="literal">org.springframework.cloud.aws.cache.config.annotation.EnableElastiCache</code>
|
||||
annotation provided by Spring Cloud AWS. The next example shows a configuration of two cache clusters.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@EnableElastiCache({@CacheClusterConfig(name = "firstCache"), @CacheClusterConfig(name = "secondCache")})</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> ApplicationConfiguration {
|
||||
}</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>If you leave the <code class="literal">value</code> attribute empty, then all the caches inside your CloudFormation stack (if available)
|
||||
will be configured automatically.</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configuring_expiry_time_for_caches" href="#_configuring_expiry_time_for_caches"></a>6.3.1 Configuring expiry time for caches</h3></div></div></div><p>The Java configuration also allows to configure the expiry time for the caches. This can be done for all
|
||||
caches using the <code class="literal">defaultExpiration</code> attribute as shown in the example below.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@EnableElastiCache(defaultExpiration = 23)</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> ApplicationConfiguration {
|
||||
}</pre><p>The expiration can be defined on a cache level using the <code class="literal">@CacheClusterConfig</code> annotations expiration attribute as shown below (using seconds as
|
||||
the value).</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@EnableElastiCache({@CacheClusterConfig(name = "firstCache", expiration = 23), @CacheClusterConfig(name = "secondCache", expiration = 42)})</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> ApplicationConfiguration {
|
||||
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_caching_in_spring_boot" href="#_configuring_caching_in_spring_boot"></a>6.4 Configuring caching in Spring Boot</h2></div></div></div><p>The caches will automatically be configured in Spring Boot without any explicit configuration property.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_caching" href="#_using_caching"></a>6.5 Using caching</h2></div></div></div><p>Based on the configuration of the cache, developers can annotate their methods to use the caching for method return values.
|
||||
The next example contains a caching declaration for a service for which the return values should be cached</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Service</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> ExpensiveService {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Cacheable("CacheCluster")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> String calculateExpensiveValue(String key) {
|
||||
...
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_memcached_client_implementation" href="#_memcached_client_implementation"></a>6.6 Memcached client implementation</h2></div></div></div><p>There are different memcached client implementations available for Java, the most prominent ones are
|
||||
<a class="link" href="https://github.com/couchbase/spymemcached" target="_top">Spymemcached</a> and <a class="link" href="https://github.com/killme2008/xmemcached" target="_top">XMemcached</a>.
|
||||
Amazon AWS supports a dynamic configuration and delivers an enhanced memcached client based on Spymemcached to support the
|
||||
<a class="link" href="http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html" target="_top">auto-discovery</a> of new nodes based on
|
||||
a central configuration endpoint.</p><p>Spring Cloud AWS relies on the Amazon ElastiCache Client implementation and therefore has a dependency on that.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_cloudformation_2" href="#_using_cloudformation_2"></a>6.7 Using CloudFormation</h2></div></div></div><p>Amazon ElastiCache clusters can also be configured within a stack and then be used by applications. Spring Cloud AWS
|
||||
also supports the lookup of stack-configured cache clusters by their logical name with the resolution to the physical
|
||||
name. The example below shows a cache cluster configuration inside a CloudFormation template.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"CacheCluster"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::ElastiCache::CacheCluster"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AutoMinorVersionUpgrade"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"true"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Engine"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"memcached"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"CacheNodeType"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"cache.t2.micro"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"CacheSubnetGroupName"</span> : <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"sample"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"NumCacheNodes"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"VpcSecurityGroupIds"</span>: [<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"sample1"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>The cache cluster can then be used with the name <code class="literal">CacheCluster</code> inside the application configuration as shown below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-cache:cache-cluster</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"CacheCluster"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">expiration</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"15"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-cache:cache-manager></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans></span></pre><p>With the configuration above the application can be deployed with multiple stacks on different environments
|
||||
without any configuration change inside the application.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__messaging.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__data_access_with_jdbc.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5. Messaging </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 7. Data Access with JDBC</td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,152 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>3. Cloud environment</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__basic_setup.html" title="2. Basic setup"><link rel="next" href="multi__managing_cloud_environments.html" title="4. Managing cloud environments"></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. Cloud environment</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__basic_setup.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__managing_cloud_environments.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_cloud_environment" href="#_cloud_environment"></a>3. Cloud environment</h1></div></div></div><p>Applications often need environment specific configuration information, especially in changing environments like in the
|
||||
Amazon cloud environment. Spring Cloud AWS provides a support to retrieve and use environment specific data inside the
|
||||
application context using common Spring mechanisms like property placeholder or the Spring expression language.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_retrieving_instance_metadata" href="#_retrieving_instance_metadata"></a>3.1 Retrieving instance metadata</h2></div></div></div><p><a class="link" href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html" target="_top">Instance metadata</a> are available inside an
|
||||
EC2 environment. The metadata can be queried using a special HTTP address that provides the instance metadata. Spring Cloud
|
||||
AWS enables application to access this metadata directly in expression or property placeholder without the need to call
|
||||
an external HTTP service.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_enabling_instance_metadata_support_with_xml" href="#_enabling_instance_metadata_support_with_xml"></a>3.1.1 Enabling instance metadata support with XML</h3></div></div></div><p>The instance metadata retrieval support is enabled through an XML element like the standard property placeholder in Spring.
|
||||
The following code sample demonstrates the activation of the instance metadata support inside an application context.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-instance-data</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>Instance metadata can be retrieved without an authorized service call, therefore the configuration above does not require
|
||||
any region or security specific configuration.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_enabling_instance_metadata_support_with_java" href="#_enabling_instance_metadata_support_with_java"></a>3.1.2 Enabling instance metadata support with Java</h3></div></div></div><p>The instance metadata can also be configured within a Java configuration class without the need for an XML configuration.
|
||||
The next example shows a typical Spring <code class="literal">@Configuration</code> class that enables the instance metadata with the
|
||||
<code class="literal">org.springframework.cloud.aws.context.config.annotation.EnableInstanceData</code></p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@EnableContextInstanceData</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">static</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> ApplicationConfiguration {
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_enabling_instance_metadata_support_in_spring_boot" href="#_enabling_instance_metadata_support_in_spring_boot"></a>3.1.3 Enabling instance metadata support in Spring Boot</h3></div></div></div><p>The instance metadata is automatically available in a Spring Boot application as a property source if the application
|
||||
is running on an EC2 instance.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_using_instance_metadata" href="#_using_instance_metadata"></a>3.1.4 Using instance metadata</h3></div></div></div><p>Instance metadata can be used in XML, Java placeholders and expressions. The example below demonstrates the usage of
|
||||
instance metadata inside an XML file using placeholders and also the expression referring to the special variable <code class="literal">environment</code></p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><bean</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">class</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"org.springframework.cloud.aws....SimpleConfigurationBean"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><property</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"value1"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">value</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"#{environment.ami-id}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><property</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"value2"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">value</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"#{environment.hostname}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><property</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"value3"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">value</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${instance-type}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><property</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"value4"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">value</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${instance-id}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></bean></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>Instance metadata can also be injected with the Spring <code class="literal">org.springframework.beans.factory.annotation.Value</code> annotation
|
||||
directly into Java fields. The next example demonstrates the use of instance metadata inside a Spring bean.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Component</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> ApplicationInfoBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${ami-id:N/A}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String amiId;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${hostname:N/A}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String hostname;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${instance-type:N/A}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String instanceType;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${services/domain:N/A}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String serviceDomain;
|
||||
}</pre><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>Every instance metadata can be accessed by the key available in the <a class="link" href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html" target="_top">instance metadata service</a>
|
||||
Nested properties can be accessed by separating the properties with a slash ('/').</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_using_instance_user_data" href="#_using_instance_user_data"></a>3.1.5 Using instance user data</h3></div></div></div><p>Besides the default instance metadata it is also possible to configure user data on each instance. This user data is retrieved and
|
||||
parsed by Spring Cloud AWS. The user data can be defined while starting an EC2 instance with the application. Spring Cloud AWS
|
||||
expects the format <code class="literal"><key>:<value>;<key>:<value></code> inside the user data so that it can parse the string and extract the key value pairs.</p><p>The user data can be configured using either the management console shown below or a <a class="link" href="http://aws.amazon.com/cloudformation/aws-cloudformation-templates/" target="_top">CloudFormation template</a>.</p><div class="informalfigure"><div class="mediaobject"><img src="images/cloud-environment-user-data.png" alt="User data in the management console"></div></div><p>A CloudFormation template snippet for the configuration of the user data is outlined below:</p><pre class="programlisting">...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Resources"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"ApplicationServerInstance"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::EC2::Instance"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"ImageId"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"ami-6a56b81d"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"UserData"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Fn::Base64"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"data1:value1;data2:value2"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">},</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"InstanceType"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"t1.micro"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span>
|
||||
...</pre><p>The user data can be accessed directly in the application context like the instance metadata through placeholders
|
||||
or expressions.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Component</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> SecondConfigurationBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${data1}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String firstDataOption;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("${data2}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String secondDataOption;
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_using_instance_tags" href="#_using_instance_tags"></a>3.1.6 Using instance tags</h3></div></div></div><p>User configured properties can also be configured with tags instead of user data. Tags are a global concept in the context
|
||||
of Amazon Web services and used in different services. Spring Cloud AWS supports instance tags also across different
|
||||
services. Compared to user data, user tags can be updated during runtime, there is no need to stop and restart
|
||||
the instance.</p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p><a class="link" href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" target="_top">User data</a> can also be used to execute scripts
|
||||
on instance startup. Therefore it is useful to leverage instance tags for user configuration and user data to execute scripts
|
||||
on instance startup.</p></td></tr></table></div><p>Instance specific tags can be configured on the instance level through the management console outlined below and
|
||||
like user data also with a CloudFormation template shown afterwards.</p><div class="informalfigure"><div class="mediaobject"><img src="images/cloud-environment-instance-tags.png" alt="Instance data in the management console"></div></div><p>A CloudFormation template snippet for the configuration of the instance tags is outlined below:</p><pre class="programlisting">...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Resources"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"UserTagAndUserDataInstance"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::EC2::Instance"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"ImageId"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"ami-6a56b81d"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"InstanceType"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"t1.micro"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Tags"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Key"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tag1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Value"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tagv1"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Key"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tag3"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Value"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tagv3"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Key"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tag2"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Value"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tagv2"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Key"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tag4"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Value"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"tagv4"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</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>To retrieve the instance tags, Spring Cloud AWS has to make authenticated requests and therefore it will need the region
|
||||
and security configuration before actually resolving the placeholders. Also because the instance tags are not available while starting
|
||||
the application context, they can only be referenced as expressions and not with placeholders. The <code class="literal">context-instance-data</code>
|
||||
element defines an attribute <code class="literal">user-tags-map</code> that will create a map in the application context for the name. This map
|
||||
can then be queried using expression for other bean definitions.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-instance-data</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">user-tags-map</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"instanceData"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>A java bean might resolve expressions with the <code class="literal">@Value</code> annotation.</p><pre class="programlisting"><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> SimpleConfigurationBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("#{instanceData.tag1}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String value1;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("#{instanceData.tag2}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String value2;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("#{instanceData.tag3}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String value3;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("#{instanceData.tag4}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String value4;
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configuring_custom_ec2_client" href="#_configuring_custom_ec2_client"></a>3.1.7 Configuring custom EC2 client</h3></div></div></div><p>In some circumstances it is necessary to have a custom EC2 client to retrieve the instance information. The
|
||||
<code class="literal">context-instance-data</code> element supports a custom EC2 client with the <code class="literal">amazon-ec2</code> attribute. The next
|
||||
example shows the use of a custom EC2 client that might have a special configuration in place.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-credentials>....</aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-instance-data</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">amazon-ec2</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myCustomClient"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><bean</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myCustomClient"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">class</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"com.amazonaws.services.ec2.AmazonEC2Client"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></bean></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_injecting_the_default_ec2_client" href="#_injecting_the_default_ec2_client"></a>3.1.8 Injecting the default EC2 client</h3></div></div></div><p>If there are user tags configured for the instance data (see above) Spring Cloud AWS configures an EC2 client with
|
||||
the specified region and security credentials. Application developers can inject the EC2 client directly into their code using the <code class="literal">@Autowired</code> annotation.</p><pre class="programlisting"><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> ApplicationService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> AmazonEC2 amazonEc2;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> ApplicationService(AmazonEC2 amazonEc2) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.amazonEc2 = amazonEc2;
|
||||
}
|
||||
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_integrating_your_spring_cloud_application_with_the_aws_parameter_store" href="#_integrating_your_spring_cloud_application_with_the_aws_parameter_store"></a>3.2 Integrating your Spring Cloud application with the AWS Parameter Store</h2></div></div></div><p>Spring Cloud provides support for centralized configuration, which can be read and made available as a regular Spring
|
||||
<code class="literal">PropertySource</code> when the application is started. The Parameter Store Configuration allows you to use this mechanism
|
||||
with the <a class="link" href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html" target="_top">AWS Parameter Store</a>.</p><p>Simply add a dependency on the <code class="literal">spring-cloud-starter-aws-parameter-store-config</code> starter module to activate the support.
|
||||
The support is similar to the support provided for the Spring Cloud Config Server or Consul’s key-value store:
|
||||
configuration parameters can be defined to be shared across all services or for a specific service and can be
|
||||
profile-specific. Encrypted values will be decrypted when retrieved.</p><p>All configuration parameters are retrieved from a common path prefix, which defaults to <code class="literal">/config</code>. From there shared
|
||||
parameters are retrieved from a path that defaults to <code class="literal">application</code> and service-specific parameters use a path that
|
||||
defaults to the configured <code class="literal">spring.application.name</code>. You can use both dots and forward slashes to specify the names
|
||||
of configuration keys. Names of activated profiles will be appended to the path using a separator that defaults to an
|
||||
underscore.</p><p>That means that for a service called <code class="literal">my-service</code> the module by default would find and use these parameters:</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">parameter key</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">Spring property</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><code class="literal">/config/application/cloud.aws.stack.name</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">cloud.aws.stack.name</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Shared by all services that have the Configuration support enabled. Can be overridden with a service- or profile-specific property.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">/config/application_production/cloud.aws.stack.name</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">cloud.aws.stack.name</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Shared by all services that have the Configuration support enabled and have a <code class="literal">production</code> Spring profile activated.
|
||||
Can be overridden with a service-specific property.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">/config/my-service/cloud/aws/stack/auto</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">cloud.aws.stack.auto</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Specific to the <code class="literal">my-service</code> service. Note that slashes in the key path are replaced with dots.</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">/config/my-service_production/cloud/aws/stack/auto</code></p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">cloud.aws.stack.auto</code></p></td><td style="" align="left" valign="top"><p>Specific to the <code class="literal">my-service</code> service when a <code class="literal">production</code> Spring profile is activated.</p></td></tr></tbody></table></div><p>Note that this module does not support full configuration files to be used as parameter values like e.g. Spring Cloud Consul does:
|
||||
AWS parameter values are limited to 4096 characters, so we support individual Spring properties to be configured only.</p><p>You can configure the following settings in a Spring Cloud <code class="literal">bootstrap.properties</code> or <code class="literal">bootstrap.yml</code> file
|
||||
(note that relaxed property binding is applied, so you don’t have to use this exact syntax):</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">property</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">default</th><th style="border-bottom: 0.5pt solid ; " align="left" valign="top">explanation</th></tr></thead><tbody><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.prefix</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">/config</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Prefix indicating first level for every property loaded from the Parameter Store.
|
||||
Value must start with a forward slash followed by one or more valid path segments or be empty.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.defaultContext</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">application</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Name of the context that defines properties shared across all services</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.profileSeparator</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">_</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>String that separates an appended profile from the context name. Note that an AWS parameter key can only contain
|
||||
dots, dashes and underscores next to alphanumeric characters.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.failFast</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">true</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Indicates if an error while retrieving the parameters should fail starting the application.</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.name</code></p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>the configured value for <code class="literal">spring.application.name</code></p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>Name to use when constructing the path for the properties to look up for this specific service.</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">aws.paramstore.enabled</code></p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p><code class="literal">true</code></p></td><td style="" align="left" valign="top"><p>Can be used to disable the Parameter Store Configuration support even though the auto-configuration is on the classpath.</p></td></tr></tbody></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__basic_setup.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__managing_cloud_environments.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2. Basic setup </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 4. Managing cloud environments</td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,187 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>7. Data Access with JDBC</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__caching.html" title="6. Caching"><link rel="next" href="multi__sending_mails.html" title="8. Sending mails"></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. Data Access with JDBC</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__caching.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__sending_mails.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_data_access_with_jdbc" href="#_data_access_with_jdbc"></a>7. Data Access with JDBC</h1></div></div></div><p>Spring has a broad support of data access technologies built on top of JDBC like <code class="literal">JdbcTemplate</code> and dedicated ORM (JPA,
|
||||
Hibernate support). Spring Cloud AWS enables application developers to re-use their JDBC technology of choice and access the
|
||||
<a class="link" href="http://aws.amazon.com/rds/" target="_top">Amazon Relational Database Service</a> with a declarative configuration. The main support provided by Spring
|
||||
Cloud AWS for JDBC data access are:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Automatic data source configuration and setup based on the Amazon RDS database instance.</li><li class="listitem">Automatic read-replica detection and configuration for Amazon RDS database instances.</li><li class="listitem">Retry-support to handle exception during Multi-AZ failover inside the data center.</li></ul></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_data_source" href="#_configuring_data_source"></a>7.1 Configuring data source</h2></div></div></div><p>Before using and configuring the database support, the application has to include the respective module dependency
|
||||
into its Maven configuration. Spring Cloud AWS JDBC support comes as a separate module to allow the modularized use of the
|
||||
modules.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_maven_dependency_configuration_2" href="#_maven_dependency_configuration_2"></a>7.1.1 Maven dependency configuration</h3></div></div></div><p>The Spring Cloud AWS JDBC module comes as a standalone module and can be imported with the following dependency declaration.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-aws-jdbc<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>{spring-cloud-version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_basic_data_source_configuration" href="#_basic_data_source_configuration"></a>7.1.2 Basic data source configuration</h3></div></div></div><p>The data source configuration requires the security and region configuration as a minimum allowing Spring Cloud AWS to retrieve
|
||||
the database metadata information with the Amazon RDS service. Spring Cloud AWS provides an additional <code class="literal">jdbc</code> specific namespace
|
||||
to configure the data source with the minimum attributes as shown in the example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:xsi</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:jdbc</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/jdbc"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/jdbc
|
||||
http://www.springframework.org/schema/cloud/aws/jdbc/spring-cloud-aws-jdbc.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"..."</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myRdsDatabase"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">password</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${rdsPassword}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></jdbc:data-source></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>The minimum configuration parameters are a unique <code class="literal">id</code> for the data source, a valid <code class="literal">db-instance-identifier</code> attribute
|
||||
that points to a valid Amazon RDS database instance. The master user password for the master user. If there is another
|
||||
user to be used (which is recommended) then the <code class="literal">username</code> attribute can be set.</p><p>With this configuration Spring Cloud AWS fetches all the necessary metadata and creates a
|
||||
<a class="link" href="http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html" target="_top">Tomcat JDBC pool</a> with the default properties. The data source
|
||||
can be later injected into any Spring Bean as shown below:</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Service</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> SimpleDatabaseService <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">implements</span> DatabaseService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> JdbcTemplate jdbcTemplate;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SimpleDatabaseService(DataSource dataSource) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.jdbcTemplate = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> JdbcTemplate(dataSource);
|
||||
}
|
||||
}</pre><p>It is possible to qualify the data source injection point with an <code class="literal">@Qualifier</code> annotation to allow multiple data source
|
||||
configurations inside one application context and still use auto-wiring.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_data_source_pool_configuration" href="#_data_source_pool_configuration"></a>7.1.3 Data source pool configuration</h3></div></div></div><p>Spring Cloud AWS creates a new Tomcat JDBC pool with the default properties. Often these default properties do not meet the
|
||||
requirements of the application with regards to pool size and other settings. The data source configuration supports the configuration
|
||||
of all valid pool properties with a nested XML element. The following example demonstrates the re-configuration of the data source
|
||||
with custom pool properties.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">..></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"..."</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myRdsDatabase"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">password</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${rdsPassword}"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:pool-attributes</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">initialSize</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"1"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">maxActive</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"200"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">minIdle</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"10"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">testOnBorrow</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"true"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">validationQuery</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"SELECT 1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></jdbc:data-source></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>A full list of all configuration attributes with their value is available <a class="link" href="http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html" target="_top">here</a>.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_data_source_with_java_config" href="#_configuring_data_source_with_java_config"></a>7.2 Configuring data source with Java config</h2></div></div></div><p>Spring Cloud AWS also supports the configuration of the data source within an <code class="literal">@Configuration</code> class. The
|
||||
<code class="literal">org.springframework.cloud.aws.jdbc.config.annotation.EnableRdsInstance</code> annotation can be used to configure one data
|
||||
source. Multiple ones can be used to configure more then one data source. Each annotation will generate exactly one
|
||||
data source bean.</p><p>The class below shows a data source configuration inside a configuration class</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@EnableRdsInstance(dbInstanceIdentifier = "test",password = "secret", readReplicaSupport = true)</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> ApplicationConfiguration {
|
||||
}</pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>The configuration attributes are the same in the XML element. The required attributes are also the same
|
||||
for the XML configuration (the <code class="literal">dbInstanceIdentifier</code> and <code class="literal">password</code> attribute)</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_java_based_data_source_pool_configuration" href="#_java_based_data_source_pool_configuration"></a>7.2.1 Java based data source pool configuration</h3></div></div></div><p>It is also possible to override the pool configuration with custom values. Spring Cloud AWS provides a
|
||||
<code class="literal">org.springframework.cloud.aws.jdbc.config.annotation.RdsInstanceConfigurer</code> that creates a
|
||||
<code class="literal">org.springframework.cloud.aws.jdbc.datasource.DataSourceFactory</code> which might contain custom pool attributes. The next
|
||||
examples shows the implementation of one configurer that overrides the validation query and the initial size.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@EnableRdsInstance(dbInstanceIdentifier = "test",password = "secret")</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> ApplicationConfiguration {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> RdsInstanceConfigurer instanceConfigurer() {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> RdsInstanceConfigurer() {
|
||||
<em><span class="hl-annotation" style="color: gray">@Override</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> DataSourceFactory getDataSourceFactory() {
|
||||
TomcatJdbcDataSourceFactory dataSourceFactory = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> TomcatJdbcDataSourceFactory();
|
||||
dataSourceFactory.setInitialSize(<span class="hl-number">10</span>);
|
||||
dataSourceFactory.setValidationQuery(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"SELECT 1 FROM DUAL"</span>);
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> dataSourceFactory;
|
||||
}
|
||||
};
|
||||
}
|
||||
}</pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>This class returns an anonymous class of type <code class="literal">org.springframework.cloud.aws.jdbc.config.annotation.RdsInstanceConfigurer</code>,
|
||||
which might also of course be a standalone class.</p></td></tr></table></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_data_source_in_spring_boot" href="#_configuring_data_source_in_spring_boot"></a>7.3 Configuring data source in Spring Boot</h2></div></div></div><p>The data sources can also be configured using the Spring Boot configuration files. Because of the dynamic number of
|
||||
data sources inside one application, the Spring Boot properties must be configured for each data source.</p><p>A data source configuration consists of the general property name <code class="literal">cloud.aws.rds.<instanceName></code> for the data source identifier
|
||||
following the sub properties for the particular data source where <code class="literal">instanceName</code> is the name of the concrete instance. The table below
|
||||
outlines all properties for a data source using <code class="literal">test</code> as the instance identifier.</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">property</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">example</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>cloud.aws.rds.test</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"> </td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The configuration property that configures a data source with the name test</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.rds.test.password</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>verySecret</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The password for the db instance test</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.rds.test.username</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>admin</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The username for the db instance test (optional)</p></td></tr><tr><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.rds.test.readReplicaSupport</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>true</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>If read-replicas should be used for the data source (see below)</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.rds.test.databaseName</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>fooDb</p></td><td style="" align="left" valign="top"><p>Custom database name if the default one from rds should not be used</p></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_read_replica_configuration" href="#_read_replica_configuration"></a>7.4 Read-replica configuration</h2></div></div></div><p>Amazon RDS allows to use <a class="link" href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html" target="_top">MySQL read-replica</a>
|
||||
instances to increase the overall throughput of the database by offloading read data access to one or more read-replica
|
||||
slaves while maintaining the data in one master database.</p><p>Spring Cloud AWS supports the use of read-replicas in combination with Spring read-only transactions. If the read-replica
|
||||
support is enabled, any read-only transaction will be routed to a read-replica instance while using the master database
|
||||
for write operations.</p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left">Caution</th></tr><tr><td align="left" valign="top"><p>Using read-replica instances does not guarantee strict <a class="link" href="http://en.wikipedia.org/wiki/ACID" target="_top">ACID</a> semantics for the database
|
||||
access and should be used with care. This is due to the fact that the read-replica might be behind and a write might not
|
||||
be immediately visible to the read transaction. Therefore it is recommended to use read-replica instances only for transactions that read
|
||||
data which is not changed very often and where outdated data can be handled by the application.</p></td></tr></table></div><p>The read-replica support can be enabled with the <code class="literal">read-replica</code> attribute in the datasource configuration.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">..></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><jdbc:data-source</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"RdsSingleMicroInstance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">password</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${rdsPassword}"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">read-replica-support</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"true"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></jdbc:data-source></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>Spring Cloud AWS will search for any read-replica that is created for the master database and route the read-only transactions
|
||||
to one of the read-replicas that are available. A business service that uses read-replicas can be implemented like shown
|
||||
in the example.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Service</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> SimpleDatabaseService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> JdbcTemplate jdbcTemplate;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SimpleDatabaseService(DataSource dataSource) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.jdbcTemplate = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Transactional(readOnly = true)</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> Person loadAll() {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// read data on the read replica</span>
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Transactional</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">void</span> updatePerson(Person person) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// write data into database</span>
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_failover_support" href="#_failover_support"></a>7.5 Failover support</h2></div></div></div><p>Amazon RDS supports a <a class="link" href="http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.html" target="_top">Multi-AZ</a> fail-over if
|
||||
one availability zone is not available due to an outage or failure of the primary instance. The replication is synchronous
|
||||
(compared to the read-replicas) and provides continuous service. Spring Cloud AWS supports a Multi-AZ failover with a retry
|
||||
mechanism to recover transactions that fail during a Multi-AZ failover.</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>In most cases it is better to provide direct feedback to a user instead of trying potentially long and frequent retries within
|
||||
a user interaction. Therefore the fail-over support is primarily useful for batch application or applications where the
|
||||
responsiveness of a service call is not critical.</p></td></tr></table></div><p>The Spring Cloud AWS JDBC module provides a retry interceptor that can be used to decorate services with an interceptor.
|
||||
The interceptor will retry the database operation again if there is a temporary error due to a Multi-AZ failover. A Multi-AZ
|
||||
failover typically lasts only a couple of seconds, therefore a retry of the business transaction will likely succeed.</p><p>The interceptor can be configured as a regular bean and then be used by a pointcut expression to decorate the respective
|
||||
method calls with the interceptor. The interceptor must have a configured database to retrieve the current status (if it
|
||||
is a temporary fail-over or a permanent error) from the Amazon RDS service.</p><p>The configuration for the interceptor can be done with a custom element from the Spring Cloud AWS jdbc namespace and
|
||||
will be configured like shown:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">..></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><jdbc:retry-interceptor</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myInterceptor"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myRdsDatabase"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">max-number-of-retries</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"10"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>The interceptor itself can be used with any Spring advice configuration to wrap the respective service. A pointcut
|
||||
for the services shown in the chapter before can be defined as follows:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">..></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aop:config></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aop:advisor</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">advice-ref</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myInterceptor"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">pointcut</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"bean(simpleDatabaseService)"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">order</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aop:config></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left">Caution</th></tr><tr><td align="left" valign="top"><p>It is important that the interceptor is called outside the transaction interceptor to ensure that the whole transaction
|
||||
will be re-executed. Configuring the interceptor inside the transaction interceptor will lead to a permanent error because
|
||||
the broken connection will never be refreshed.</p></td></tr></table></div><p>The configuration above in combination with a transaction configuration will produce the following proxy configuration
|
||||
for the service.</p><div class="informalfigure"><div class="mediaobject"><img src="images/jdbc-retry-interceptor.png" alt="Retry interceptor"></div></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_cloudformation_support" href="#_cloudformation_support"></a>7.6 CloudFormation support</h2></div></div></div><p>Spring Cloud AWS supports database instances that are configured with CloudFormation. Spring Cloud AWS can use the logical
|
||||
name inside the database configuration and lookup the concrete database with the generated physical resource name. A database
|
||||
configuration can be easily configured in CloudFormation with a template definition that might look like the following
|
||||
example.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"myRdsDatabase"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::RDS::DBInstance"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AllocatedStorage"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"5"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"DBInstanceClass"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"db.t1.micro"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"DBName"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Engine"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"mysql"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"MasterUsername"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"admin"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"MasterUserPassword"</span>: {<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Ref"</span>:<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"RdsPassword"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">},</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"readReplicaDatabase"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::RDS::DBInstance"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AllocatedStorage"</span> : <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"5"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"SourceDBInstanceIdentifier"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Ref"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"myRdsDatabase"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">},</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"DBInstanceClass"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"db.t1.micro"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>The database can then be configured using the name set in the template. Also, the read-replica can
|
||||
be enabled to use the configured read-replica database in the application. A configuration to use the configured
|
||||
database is outlined below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:stack-configuration/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myRdsDatabase"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">password</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${rdsPassword}"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">read-replica-support</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"true"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_database_tags" href="#_database_tags"></a>7.7 Database tags</h2></div></div></div><p>Amazon RDS instances can also be configured using RDS database specific tags, allowing users to configure database specific
|
||||
configuration metadata with the database. Database instance specific tags can be configured using the <code class="literal">user-tags-map</code> attribute
|
||||
on the <code class="literal">data-source</code> element. Configure the tags support like in the example below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myRdsDatabase"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">password</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"${rdsPassword}"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">user-tags-map</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"dbTags"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre><p>That allows the developer to access the properties in the code using expressions like shown in the class below:</p><pre class="programlisting"><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> SampleService {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Value("#{dbTags['aws:cloudformation:aws:cloudformation:stack-name']}")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> String stackName;
|
||||
}</pre><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 database tag <code class="literal">aws:cloudformation:aws:cloudformation:stack-name</code> is a default tag that is created if the
|
||||
database is configured using CloudFormation.</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__caching.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__sending_mails.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6. Caching </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 8. Sending mails</td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,85 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>4. Managing cloud environments</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__cloud_environment.html" title="3. Cloud environment"><link rel="next" href="multi__messaging.html" title="5. Messaging"></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. Managing cloud environments</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__cloud_environment.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__messaging.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_managing_cloud_environments" href="#_managing_cloud_environments"></a>4. Managing cloud environments</h1></div></div></div><p>Managing environments manually with the management console does not scale and can become error-prone with the increasing
|
||||
complexity of the infrastructure. Amazon Web services offers a <a class="link" href="http://aws.amazon.com/cloudformation/" target="_top">CloudFormation</a>
|
||||
service that allows to define stack configuration templates and bootstrap the whole infrastructure with the services.
|
||||
In order to allow multiple stacks in parallel, each resource in the stack receives a unique physical name that contains
|
||||
some arbitrary generated name. In order to interact with the stack resources in a unified way Spring Cloud AWS allows
|
||||
developers to work with logical names instead of the random physical ones.</p><p>The next graphics shows a typical stack configuration.</p><div class="informalfigure"><div class="mediaobject"><img src="images/cloudformation-overview.png" alt="CloudFormation overview"></div></div><p>The <span class="strong"><strong>Template File</strong></span> describes all stack resources with their <span class="emphasis"><em>logical name</em></span>. The <span class="strong"><strong>CloudFormation</strong></span> service parses the stack
|
||||
template file and creates all resources with their <span class="emphasis"><em>physical name</em></span>. The application can use all the stack configured resources
|
||||
with the <span class="emphasis"><em>logical name</em></span> defined in the template. Spring Cloud AWS resolves all <span class="emphasis"><em>logical names</em></span> into the respective
|
||||
<span class="emphasis"><em>physical name</em></span> for the application developer.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_automatic_cloudformation_configuration" href="#_automatic_cloudformation_configuration"></a>4.1 Automatic CloudFormation configuration</h2></div></div></div><p>If the application runs inside a stack (because the underlying EC2 instance has been bootstrapped within the stack), then
|
||||
Spring Cloud AWS will automatically detect the stack and resolve all resources from the stack. Application developers
|
||||
can use all the logical names from the stack template to interact with the services. In the example below, the database
|
||||
resource is configured using a CloudFormation template, defining a logical name for the database instance.</p><pre class="programlisting">"applicationDatabase": {
|
||||
"Type": "AWS::RDS::DBInstance",
|
||||
"Properties": {
|
||||
"AllocatedStorage": "5",
|
||||
"DBInstanceClass": "db.t1.micro",
|
||||
"DBName": "test"
|
||||
...
|
||||
]
|
||||
}
|
||||
}</pre><p>The datasource is then created and will receive a physical name (e.g. ir142c39k6o5irj) as the database service name. Application
|
||||
developers can still use the logical name (in this case <code class="literal">applicationDatabase</code>) to interact with the database. The example
|
||||
below shows the stack configuration which is defined by the element <code class="literal">aws-context:stack-configuration</code> and resolves automatically
|
||||
the particular stack. The <code class="literal">data-source</code> element uses the logical name for the <code class="literal">db-instance-identifier</code> attribute to work with
|
||||
the database.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:xsi</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-context</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context
|
||||
http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">..</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:stack-configuration/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><jdbc:data-source</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">db-instance-identifier</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"applicationDatabase"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>Further detailed information on the Amazon RDS configuration and setup can be found in the respective chapter in this
|
||||
documentation.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_manual_cloudformation_configuration" href="#_manual_cloudformation_configuration"></a>4.2 Manual CloudFormation configuration</h2></div></div></div><p>If the application is not running inside a stack configured EC2 instance, then the stack configuration must be configured
|
||||
manually. The configuration consists of an additional element attribute <code class="literal">stack-name</code> that will be used to resolve all the
|
||||
respective stack configuration information at runtime.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">....></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:stack-configuration</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">stack-name</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"myStackName"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_cloudformation_configuration_with_java_config_classes" href="#_cloudformation_configuration_with_java_config_classes"></a>4.3 CloudFormation configuration with Java config classes</h2></div></div></div><p>Spring Cloud AWS also supports the configuration of the CloudFormation support within Java classes avoiding the use of
|
||||
XML inside the application configuration. Spring Cloud AWS provides the annotation
|
||||
<code class="literal">og.springframework.cloud.aws.context.config.annotation.EnableStackConfiguration</code> that allows the automatic and manual
|
||||
stack configuration. The next example shows a configuration class that configures the CloudFormation support with an
|
||||
explicit stack name (here <code class="literal">manualStackName</code>).</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Configuration</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@EnableStackConfiguration(stackName = "manualStackName")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span> ApplicationConfiguration {
|
||||
}</pre><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>Do not define the <code class="literal">stackName</code> attribute if an automatic stack name should be enabled.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_cloudformation_configuration_in_spring_boot" href="#_cloudformation_configuration_in_spring_boot"></a>4.4 CloudFormation configuration in Spring Boot</h2></div></div></div><p>Spring Cloud AWS also supports the configuration of the CloudFormation support within the Spring Boot configuration. The
|
||||
manual and automatic stack configuration can be defined with properties that are described in the table below.</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"></colgroup><thead><tr><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">property</th><th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top">example</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>cloud.aws.stack.name</p></td><td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; " align="left" valign="top"><p>myStackName</p></td><td style="border-bottom: 0.5pt solid ; " align="left" valign="top"><p>The name of the manually configured stack name that will be used to retrieve the resources.</p></td></tr><tr><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>cloud.aws.stack.auto</p></td><td style="border-right: 0.5pt solid ; " align="left" valign="top"><p>true</p></td><td style="" align="left" valign="top"><p>Enables the automatic stack name detection for the application.</p></td></tr></tbody></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_manual_name_resolution" href="#_manual_name_resolution"></a>4.5 Manual name resolution</h2></div></div></div><p>Spring Cloud AWS uses the CloudFormation stack to resolve all resources internally using the logical names. In some circumstances
|
||||
it might be needed to resolve the physical name inside the application code. Spring Cloud AWS provides a pre-configured
|
||||
service to resolve the physical stack name based on the logical name. The sample shows a manual stack resource resolution.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Service</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> ApplicationService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> ResourceIdResolver resourceIdResolver;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> ApplicationService(ResourceIdResolver resourceIdResolver) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourceIdResolver = resourceIdResolver;
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> handleApplicationLogic() {
|
||||
String physicalBucketName =
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourceIdResolver.resolveToPhysicalResourceId(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"someLogicalName"</span>);
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_stack_tags" href="#_stack_tags"></a>4.6 Stack Tags</h2></div></div></div><p>Like for the Amazon EC2 instances, CloudFormation also provides stack specific tags that can be used to
|
||||
configure stack specific configuration information and receive them inside the application. This can for example be a
|
||||
stage specific configuration property (like DEV, INT, PRD).</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">....></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:stack-configuration</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">user-tags-map</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"stackTags"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>The application can then access the stack tags with an expression like <code class="literal">#{stackTags.key1}</code>.</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_custom_cloudformation_client" href="#_using_custom_cloudformation_client"></a>4.7 Using custom CloudFormation client</h2></div></div></div><p>Like for the EC2 configuration setup, the <code class="literal">aws-context:stack-configuration</code> element supports a custom CloudFormation client
|
||||
with a special setup. The client itself can be configured using the <code class="literal">amazon-cloud-formation</code> attribute as shown in the example:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:stack-configuration</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">amazon-cloud-formation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">""</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><bean</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">class</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"com.amazonaws.services.cloudformation.AmazonCloudFormationClient"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></bean></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__cloud_environment.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__messaging.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. Cloud environment </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 5. Messaging</td></tr></table></div></body></html>
|
||||
205
spring-cloud-aws/2.0.0.RELEASE/multi/multi__messaging.html
Normal file
@@ -0,0 +1,205 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>5. Messaging</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__managing_cloud_environments.html" title="4. Managing cloud environments"><link rel="next" href="multi__caching.html" title="6. Caching"></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. Messaging</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__managing_cloud_environments.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__caching.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_messaging" href="#_messaging"></a>5. Messaging</h1></div></div></div><p>Spring Cloud AWS provides <a class="link" href="http://aws.amazon.com/sqs/" target="_top">Amazon SQS</a> and <a class="link" href="http://aws.amazon.com/sqs/" target="_top">Amazon SNS</a> integration
|
||||
that simplifies the publication and consumption of messages over SQS or SNS. While SQS fully relies on the messaging API
|
||||
introduced with Spring 4.0, SNS only partially implements it as the receiving part must be handled differently for
|
||||
push notifications.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_messaging" href="#_configuring_messaging"></a>5.1 Configuring messaging</h2></div></div></div><p>Before using and configuring the messaging support, the application has to include the respective module dependency
|
||||
into the Maven configuration. Spring Cloud AWS Messaging support comes as a separate module to allow the modularized use
|
||||
of the modules.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_maven_dependency_configuration" href="#_maven_dependency_configuration"></a>5.1.1 Maven dependency configuration</h3></div></div></div><p>The Spring Cloud AWS messaging module comes as a standalone module and can be imported with the following dependency declaration:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>org.springframework.cloud<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>spring-cloud-aws-messaging<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>{spring-cloud-version}<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span></pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sqs_support" href="#_sqs_support"></a>5.2 SQS support</h2></div></div></div><p>Amazon SQS is a hosted messaging service on the Amazon Web Service platform that provides point-to-point communication
|
||||
with queues. Compared to JMS or other message services Amazon SQS has several features and limitations that should be
|
||||
taken into consideration.</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Amazon SQS allows only <code class="literal">String</code> payloads, so any <code class="literal">Object</code> must be transformed into a String representation.
|
||||
Spring Cloud AWS has dedicated support to transfer Java objects with Amazon SQS messages by converting them to JSON.</li><li class="listitem">Amazon SQS has no transaction support, so messages might therefore be retrieved twice. Application have to be written in
|
||||
an idempotent way so that they can receive a message twice.</li><li class="listitem">Amazon SQS has a maximum message size of 256kb per message, so bigger messages will fail to be sent.</li></ul></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sending_a_message" href="#_sending_a_message"></a>5.2.1 Sending a message</h3></div></div></div><p>The <code class="literal">QueueMessagingTemplate</code> contains many convenience methods to send a message. There are send methods that specify the
|
||||
destination using a <code class="literal">QueueMessageChannel</code> object and those that specify the destination using a string which is going to
|
||||
be resolved against the SQS API. The send method that takes no destination argument uses the default destination.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> com.amazonaws.services.sqs.AmazonSQS;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
<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> SqsQueueSender {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> QueueMessagingTemplate queueMessagingTemplate;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SqsQueueSender(AmazonSQS amazonSqs) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.queueMessagingTemplate = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> QueueMessagingTemplate(amazonSqs);
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> send(String message) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.queueMessagingTemplate.send(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"physicalQueueName"</span>, MessageBuilder.withPayload(message).build());
|
||||
}
|
||||
}</pre><p>This example uses the <code class="literal">MessageBuilder</code> class to create a message with a string payload. The <code class="literal">QueueMessagingTemplate</code> is
|
||||
constructed by passing a reference to the <code class="literal">AmazonSQS</code> client. The destination in the send method is a string value that
|
||||
must match the queue name defined on AWS. This value will be resolved at runtime by the Amazon SQS client. Optionally
|
||||
a <code class="literal">ResourceIdResolver</code> implementation can be passed to the <code class="literal">QueueMessagingTemplate</code> constructor to resolve resources by
|
||||
logical name when running inside a CloudFormation stack (see <a class="xref" href="multi__managing_cloud_environments.html" title="4. Managing cloud environments">Chapter 4, <i>Managing cloud environments</i></a> for more information about
|
||||
resource name resolution).</p><p>With the messaging namespace a <code class="literal">QueueMessagingTemplate</code> can be defined in an XML configuration file.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:xsi</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-context</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-messaging</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/messaging"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/cloud/aws/context
|
||||
http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd
|
||||
http://www.springframework.org/schema/cloud/aws/messaging
|
||||
http://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:instance-profile-credentials /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:queue-messaging-template</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"queueMessagingTemplate"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><p>In this example the messaging namespace handler constructs a new <code class="literal">QueueMessagingTemplate</code>. The <code class="literal">AmazonSQS</code> client
|
||||
is automatically created and passed to the template’s constructor based on the provided credentials. If the
|
||||
application runs inside a configured CloudFormation stack a <code class="literal">ResourceIdResolver</code> is passed to the constructor (see
|
||||
<a class="xref" href="multi__managing_cloud_environments.html" title="4. Managing cloud environments">Chapter 4, <i>Managing cloud environments</i></a> for more information about resource name resolution).</p><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_using_message_converters" href="#_using_message_converters"></a>Using message converters</h4></div></div></div><p>In order to facilitate the sending of domain model objects, the <code class="literal">QueueMessagingTemplate</code> has various send methods that
|
||||
take a Java object as an argument for a message’s data content. The overloaded methods <code class="literal">convertAndSend()</code> and
|
||||
<code class="literal">receiveAndConvert()</code> in <code class="literal">QueueMessagingTemplate</code> delegate the conversion process to an instance of the <code class="literal">MessageConverter</code>
|
||||
interface. This interface defines a simple contract to convert between Java objects and SQS messages. The default
|
||||
implementation <code class="literal">SimpleMessageConverter</code> simply unwraps the message payload as long as it matches the target type. By
|
||||
using the converter, you and your application code can focus on the business object that is being sent or received via
|
||||
SQS and not be concerned with the details of how it is represented as an SQS message.</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>As SQS is only able to send <code class="literal">String</code> payloads the default converter <code class="literal">SimpleMessageConverter</code> should only be used
|
||||
to send <code class="literal">String</code> payloads. For more complex objects a custom converter should be used like the one created by the
|
||||
messaging namespace handler.</p></td></tr></table></div><p>It is recommended to use the XML messaging namespace to create <code class="literal">QueueMessagingTemplate</code> as it will set a more
|
||||
sophisticated <code class="literal">MessageConverter</code> that converts objects into JSON when Jackson is on the classpath.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:queue-messaging-template</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"queueMessagingTemplate"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.queueMessagingTemplate.convertAndSend(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"queueName"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> Person(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"John, "</span>Doe<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"));</span></pre><p>In this example a <code class="literal">QueueMessagingTemplate</code> is created using the messaging namespace. The <code class="literal">convertAndSend</code> method
|
||||
converts the payload <code class="literal">Person</code> using the configured <code class="literal">MessageConverter</code> and sends the message.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_receiving_a_message" href="#_receiving_a_message"></a>5.2.2 Receiving a message</h3></div></div></div><p>There are two ways for receiving SQS messages, either use the <code class="literal">receive</code> methods of the <code class="literal">QueueMessagingTemplate</code> or with
|
||||
annotation-driven listener endpoints. The latter is by far the more convenient way to receive messages.</p><pre class="programlisting">Person person = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.queueMessagingTemplate.receiveAndConvert(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"queueName"</span>, Person.<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">class</span>);</pre><p>In this example the <code class="literal">QueueMessagingTemplate</code> will get one message from the SQS queue and convert it to the target class
|
||||
passed as argument.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_annotation_driven_listener_endpoints" href="#_annotation_driven_listener_endpoints"></a>5.2.3 Annotation-driven listener endpoints</h3></div></div></div><p>Annotation-driven listener endpoints are the easiest way for listening on SQS messages. Simply annotate methods with
|
||||
<code class="literal">MessageMapping</code> and the <code class="literal">QueueMessageHandler</code> will route the messages to the annotated methods.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:annotation-driven-queue-listener /></span></pre><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@SqsListener("queueName")</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">void</span> queueListener(Person person) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// ...</span>
|
||||
}</pre><p>In this example a queue listener container is started that polls the SQS <code class="literal">queueName</code> passed to the <code class="literal">MessageMapping</code>
|
||||
annotation. The incoming messages are converted to the target type and then the annotated method <code class="literal">queueListener</code> is invoked.</p><p>In addition to the payload, headers can be injected in the listener methods with the <code class="literal">@Header</code> or <code class="literal">@Headers</code>
|
||||
annotations. <code class="literal">@Header</code> is used to inject a specific header value while <code class="literal">@Headers</code> injects a <code class="literal">Map<String, String></code>
|
||||
containing all headers.</p><p>Only the <a class="link" href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_Message.html" target="_top">standard
|
||||
message attributes</a> sent with an SQS message are supported. Custom attributes are currently not supported.</p><p>In addition to the provided argument resolvers, custom ones can be registered on the
|
||||
<code class="literal">aws-messaging:annotation-driven-queue-listener</code> element using the <code class="literal">aws-messaging:argument-resolvers</code> attribute (see example below).</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:annotation-driven-queue-listener></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:argument-resolvers></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><bean</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">class</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"org.custom.CustomArgumentResolver"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-messaging:argument-resolvers></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-messaging:annotation-driven-queue-listener></span></pre><p>By default the <code class="literal">SimpleMessageListenerContainer</code> creates a <code class="literal">ThreadPoolTaskExecutor</code> with computed values for the core and
|
||||
max pool sizes. The core pool size is set to twice the number of queues and the max pool size is obtained by multiplying
|
||||
the number of queues by the value of the <code class="literal">maxNumberOfMessages</code> field. If these default values do not meet the need of
|
||||
the application, a custom task executor can be set with the <code class="literal">task-executor</code> attribute (see example below).</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:annotation-driven-queue-listener</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">task-executor</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"simpleTaskExecutor"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre><div class="section"><div class="titlepage"><div><div><h4 class="title"><a name="_message_reply" href="#_message_reply"></a>Message reply</h4></div></div></div><p>Message listener methods can be annotated with <code class="literal">@SendTo</code> to send their return value to another channel. The
|
||||
<code class="literal">SendToHandlerMethodReturnValueHandler</code> uses the defined messaging template set on the
|
||||
<code class="literal">aws-messaging:annotation-driven-queue-listener</code> element to send the return value. The messaging template must implement
|
||||
the <code class="literal">DestinationResolvingMessageSendingOperations</code> interface.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:annotation-driven-queue-listener</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">send-to-message-template</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"queueMessagingTemplate"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span></pre><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@SqsListener("treeQueue")</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@SendTo("leafsQueue")</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> List<Leaf> extractLeafs(Tree tree) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// ...</span>
|
||||
}</pre><p>In this example the <code class="literal">extractLeafs</code> method will receive messages coming from the <code class="literal">treeQueue</code> and then return a
|
||||
<code class="literal">List</code> of <code class="literal">Leaf</code>s which is going to be sent to the <code class="literal">leafsQueue</code>. Note that on the
|
||||
<code class="literal">aws-messaging:annotation-driven-queue-listener</code> XML element there is an attribute <code class="literal">send-to-message-template</code>
|
||||
that specifies <code class="literal">QueueMessagingTemplate</code> as the messaging template to be used to send the return value of the message
|
||||
listener method.</p></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_the_simplemessagelistenercontainerfactory" href="#_the_simplemessagelistenercontainerfactory"></a>5.2.4 The SimpleMessageListenerContainerFactory</h3></div></div></div><p>The <code class="literal">SimpleMessageListenerContainer</code> can also be configured with Java by creating a bean of type <code class="literal">SimpleMessageListenerContainerFactory</code>.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(AmazonSQSAsync amazonSqs) {
|
||||
SimpleMessageListenerContainerFactory factory = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> SimpleMessageListenerContainerFactory();
|
||||
factory.setAmazonSqs(amazonSqs);
|
||||
factory.setAutoStartup(false);
|
||||
factory.setMaxNumberOfMessages(<span class="hl-number">5</span>);
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// ...</span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> factory;
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_consuming_aws_event_messages_with_amazon_sqs" href="#_consuming_aws_event_messages_with_amazon_sqs"></a>5.2.5 Consuming AWS Event messages with Amazon SQS</h3></div></div></div><p>It is also possible to receive AWS generated event messages with the SQS message listeners. Because
|
||||
AWS messages does not contain the mime-type header, the Jackson message converter has to be configured
|
||||
with the <code class="literal">strictContentTypeMatch</code> property false to also parse message without the proper mime type.</p><p>The next code shows the configuration of the message converter using the <code class="literal">QueueMessageHandlerFactory</code>
|
||||
and re-configuring the <code class="literal">MappingJackson2MessageConverter</code></p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Bean</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> QueueMessageHandlerFactory queueMessageHandlerFactory() {
|
||||
QueueMessageHandlerFactory factory = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> QueueMessageHandlerFactory();
|
||||
MappingJackson2MessageConverter messageConverter = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> MappingJackson2MessageConverter();
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//set strict content type match to false</span>
|
||||
messageConverter.setStrictContentTypeMatch(false);
|
||||
factory.setArgumentResolvers(Collections.<HandlerMethodArgumentResolver>singletonList(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> PayloadArgumentResolver(messageConverter)));
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">return</span> factory;
|
||||
}</pre><p>With the configuration above, it is possible to receive event notification for S3 buckets (and also other
|
||||
event notifications like elastic transcoder messages) inside <code class="literal">@SqsListener</code> annotated methods s shown below.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@SqsListener("testQueue")</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">void</span> receive(S3EventNotification s3EventNotificationRecord) {
|
||||
S3EventNotification.S3Entity s3Entity = s3EventNotificationRecord.getRecords().get(<span class="hl-number">0</span>).getS3();
|
||||
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sns_support" href="#_sns_support"></a>5.3 SNS support</h2></div></div></div><p>Amazon SNS is a publish-subscribe messaging system that allows clients to publish notification to a particular topic. Other
|
||||
interested clients may subscribe using different protocols like HTTP/HTTPS, e-mail or an Amazon SQS queue to receive the messages.</p><p>The next graphic shows a typical example of an Amazon SNS architecture.</p><div class="informalfigure"><div class="mediaobject"><img src="images/sns-overview.png" alt="SNS Overview"></div></div><p>Spring Cloud AWS supports Amazon SNS by providing support to send notifications with a <code class="literal">NotificationMessagingTemplate</code> and
|
||||
to receive notifications with the HTTP/HTTPS endpoint using the Spring Web MVC <code class="literal">@Controller</code> based programming model. Amazon
|
||||
SQS based subscriptions can be used with the annotation-driven message support that is provided by the Spring Cloud AWS messaging module.</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_sending_a_message_2" href="#_sending_a_message_2"></a>5.3.1 Sending a message</h3></div></div></div><p>The <code class="literal">NotificationMessagingTemplate</code> contains two convenience methods to send a notification. The first one specifies the
|
||||
destination using a <code class="literal">String</code> which is going to be resolved against the SNS API. The second one takes no destination
|
||||
argument and uses the default destination. All the usual send methods that are available on the <code class="literal">MessageSendingOperations</code>
|
||||
are implemented but are less convenient to send notifications because the subject must be passed as header.</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>Currently only <code class="literal">String</code> payloads can be sent using the <code class="literal">NotificationMessagingTemplate</code> as this is the expected
|
||||
type by the SNS API.</p></td></tr></table></div><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> com.amazonaws.services.sns.AmazonSNS;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">import</span> org.springframework.cloud.aws.messaging.core.NotificationMessagingTemplate;
|
||||
|
||||
<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> SnsNotificationSender {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> NotificationMessagingTemplate notificationMessagingTemplate;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SnsNotificationSender(AmazonSNS amazonSns) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.notificationMessagingTemplate = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> NotificationMessagingTemplate(amazonSns);
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> send(String subject, String message) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.notificationMessagingTemplate.sendNotification(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"physicalTopicName"</span>, message, subject);
|
||||
}
|
||||
}</pre><p>This example constructs a new <code class="literal">NotificationMessagingTemplate</code> by passing an <code class="literal">AmazonSNS</code> client as argument. In the <code class="literal">send</code>
|
||||
method the convenience <code class="literal">sendNotification</code> method is used to send a <code class="literal">message</code> with <code class="literal">subject</code> to an SNS topic. The
|
||||
destination in the <code class="literal">sendNotification</code> method is a string value that must match the topic name defined on AWS. This value
|
||||
is resolved at runtime by the Amazon SNS client. Optionally a <code class="literal">ResourceIdResolver</code> implementation can be passed to the
|
||||
<code class="literal">NotificationMessagingTemplate</code> constructor to resolve resources by logical name when running inside a CloudFormation stack.
|
||||
(See <a class="xref" href="multi__managing_cloud_environments.html" title="4. Managing cloud environments">Chapter 4, <i>Managing cloud environments</i></a> for more information about resource name resolution.)</p><p>It is recommended to use the XML messaging namespace to create <code class="literal">NotificationMessagingTemplate</code> as it will automatically
|
||||
configure the SNS client to setup the default converter.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:notification-messaging-template</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"notificationMessagingTemplate"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_annotation_driven_http_notification_endpoint" href="#_annotation_driven_http_notification_endpoint"></a>5.3.2 Annotation-driven HTTP notification endpoint</h3></div></div></div><p>SNS supports multiple endpoint types (SQS, Email, HTTP, HTTPS), Spring Cloud AWS provides support for HTTP(S) endpoints.
|
||||
SNS sends three type of requests to an HTTP topic listener endpoint, for each of them annotations are provided:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">Subscription request → <code class="literal">@NotificationSubscriptionMapping</code></li><li class="listitem">Notification request → <code class="literal">@NotificationMessageMapping</code></li><li class="listitem">Unsubscription request → <code class="literal">@NotificationUnsubscribeMapping</code></li></ul></div><p>HTTP endpoints are based on Spring MVC controllers. Spring Cloud AWS added some custom argument resolvers to extract
|
||||
the message and subject out of the notification requests.</p><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@Controller</span></em>
|
||||
<em><span class="hl-annotation" style="color: gray">@RequestMapping("/topicName")</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> NotificationTestController {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@NotificationSubscriptionMapping</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">void</span> handleSubscriptionMessage(NotificationStatus status) <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> IOException {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//We subscribe to start receive the message</span>
|
||||
status.confirmSubscription();
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@NotificationMessageMapping</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">void</span> handleNotificationMessage(<em><span class="hl-annotation" style="color: gray">@NotificationSubject</span></em> String subject, <em><span class="hl-annotation" style="color: gray">@NotificationMessage</span></em> String message) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// ...</span>
|
||||
}
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@NotificationUnsubscribeConfirmationMapping</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">void</span> handleUnsubscribeMessage(NotificationStatus status) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//e.g. the client has been unsubscribed and we want to "re-subscribe"</span>
|
||||
status.confirmSubscription();
|
||||
}
|
||||
}</pre><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Caution"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="images/caution.png"></td><th align="left">Caution</th></tr><tr><td align="left" valign="top"><p>Currently it is not possible to define the mapping URL on the method level therefore the <code class="literal">RequestMapping</code> must
|
||||
be done at type level and must contain the full path of the endpoint.</p></td></tr></table></div><p>This example creates a new Spring MVC controller with three methods to handle the three requests listed above. In order
|
||||
to resolve the arguments of the <code class="literal">handleNotificationMessage</code> methods a custom argument resolver must be registered. The
|
||||
XML configuration is listed below.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><mvc:annotation-driven></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><mvc:argument-resolvers></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><ref</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">bean</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"notificationResolver"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></mvc:argument-resolvers></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></mvc:annotation-driven></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:notification-argument-resolver</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"notificationResolver"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre><p>The <code class="literal">aws-messaging:notification-argument-resolver</code> element registers three argument resolvers:
|
||||
<code class="literal">NotificationStatusHandlerMethodArgumentResolver</code>, <code class="literal">NotificationMessageHandlerMethodArgumentResolver</code>,
|
||||
and <code class="literal">NotificationSubjectHandlerMethodArgumentResolver</code>.</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_cloudformation" href="#_using_cloudformation"></a>5.4 Using CloudFormation</h2></div></div></div><p>Amazon SQS queues and SNS topics can be configured within a stack and then be used by applications. Spring Cloud AWS
|
||||
also supports the lookup of stack-configured queues and topics by their logical name with the resolution to the physical
|
||||
name. The example below shows an SNS topic and SQS queue configuration inside a CloudFormation template.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"LogicalQueueName"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::SQS::Queue"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">},</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"LogicalTopicName"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::SNS::Topic"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">,</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Properties"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>The logical names <code class="literal">LogicalQueueName</code> and <code class="literal">LogicalTopicName</code> can then be used in the configuration and in the application
|
||||
as shown below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:queue-messaging-template</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">default-destination</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"LogicalQueueName"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-messaging:notification-messaging-template</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">default-destination</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"LogicalTopicName"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span></pre><pre class="programlisting"><em><span class="hl-annotation" style="color: gray">@SqsListener("LogicalQueueName")</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">void</span> receiveQueueMessages(Person person) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">// Logical names can also be used with messaging templates</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.notificationMessagingTemplate.sendNotification(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"anotherLogicalTopicName"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Message"</span>, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Subject"</span>);
|
||||
}</pre><p>When using the logical names like in the example above, the stack can be created on different environments without any
|
||||
configuration or code changes inside the application.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__managing_cloud_environments.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__caching.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Managing cloud environments </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 6. Caching</td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,112 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>9. Resource handling</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__sending_mails.html" title="8. Sending mails"></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">9. Resource handling</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__sending_mails.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="_resource_handling" href="#_resource_handling"></a>9. Resource handling</h1></div></div></div><p>The Spring Framework provides a <code class="literal">org.springframework.core.io.ResourceLoader</code> abstraction to load files from the filesystem,
|
||||
servlet context and the classpath. Spring Cloud AWS adds support for the <a class="link" href="http://aws.amazon.com/s3/" target="_top">Amazon S3</a> service
|
||||
to load and write resources with the resource loader and the <code class="literal">s3</code> protocol.</p><p>The resource loader is part of the context module, therefore no additional dependencies are necessary to use the resource
|
||||
handling support.</p><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_the_resource_loader" href="#_configuring_the_resource_loader"></a>9.1 Configuring the resource loader</h2></div></div></div><p>Spring Cloud AWS does not modify the default resource loader unless it encounters an explicit configuration with an XML namespace element.
|
||||
The configuration consists of one element for the whole application context that is shown below:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:xsi</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-context</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/context
|
||||
http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
...
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-resource-loader/></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_downloading_files" href="#_downloading_files"></a>9.2 Downloading files</h2></div></div></div><p>Downloading files can be done by using the <code class="literal">s3</code> protocol to reference Amazon S3 buckets and objects inside their bucket. The
|
||||
typical pattern is <code class="literal">s3://<bucket>/<object></code> where bucket is the global and unique bucket name and object is a valid object
|
||||
name inside the bucket. The object name can be a file in the <span class="emphasis"><em>root</em></span> folder of a bucket or a nested file within a directory
|
||||
inside a bucket.</p><p>The next example demonstrates the use of the resource loader to load different resources.</p><pre class="programlisting"><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> SimpleResourceLoadingBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> ResourceLoader resourceLoader;
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> resourceLoadingMethod() <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> IOException {
|
||||
Resource resource = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourceLoader.getResource(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://myBucket/rootFile.log"</span>);
|
||||
Resource secondResource = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourceLoader.getResource(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://myBucket/rootFolder/subFile"</span>);
|
||||
|
||||
InputStream inputStream = resource.getInputStream();
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment">//read file</span>
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_uploading_files" href="#_uploading_files"></a>9.3 Uploading files</h2></div></div></div><p>Since Spring Framework 3.1 the resource loader can also be used to upload files with the <code class="literal">org.springframework.core.io.WritableResource</code>
|
||||
interface which is a specialization of the <code class="literal">org.springframework.core.io.ResourceLoader</code> interface. Clients can upload files
|
||||
using the <code class="literal">WritableResource</code> interface. The next example demonstrates an upload of a resource using the resource loader.</p><pre class="programlisting"><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> SimpleResourceLoadingBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> ResourceLoader resourceLoader;
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> writeResource() <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> IOException {
|
||||
Resource resource = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourceLoader.getResource(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://myBucket/rootFile.log"</span>);
|
||||
WritableResource writableResource = (WritableResource) resource;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">try</span> (OutputStream outputStream = writableResource.getOutputStream()) {
|
||||
outputStream.write(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test"</span>.getBytes());
|
||||
}
|
||||
}
|
||||
}</pre><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_uploading_multi_part_files" href="#_uploading_multi_part_files"></a>9.3.1 Uploading multi-part files</h3></div></div></div><p>Amazon S3 supports <a class="link" href="http://docs.aws.amazon.com/AmazonS3/latest/dev/uploadobjusingmpu.html" target="_top">multi-part uploads</a> to
|
||||
increase the general throughput while uploading. Spring Cloud AWS by default only uses one thread to upload the files and
|
||||
therefore does not provide parallel upload support. Users can configure a custom <code class="literal">org.springframework.core.task.TaskExecutor</code>
|
||||
for the resource loader. The resource loader will queue multiple threads at the same time to use parallel multi-part uploads.</p><p>The configuration for a resource loader that uploads with 10 Threads looks like the following</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-resource-loader</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">task-executor</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"executor"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><task:executor</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"executor"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">pool-size</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"10"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">queue-capacity</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"0"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">rejection-policy</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"CALLER_RUNS"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td><th align="left">Warning</th></tr><tr><td align="left" valign="top"><p>Spring Cloud AWS consumes up to 5 MB (at a minimum) of memory per thread. Therefore each parallel thread will incur
|
||||
a memory footprint of 5 MB in the heap, and a thread size of 10 will consume therefore up to 50 mb of heap space. Spring Cloud
|
||||
AWS releases the memory as soon as possible. Also, the example above shows that there is no <code class="literal">queue-capacity</code> configured,
|
||||
because queued requests would also consume memory.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_uploading_with_the_transfermanager" href="#_uploading_with_the_transfermanager"></a>9.3.2 Uploading with the TransferManager</h3></div></div></div><p>The Amazon SDK also provides a high-level abstraction that is useful to upload files, also with multiple threads using
|
||||
the multi-part functionality. A <code class="literal">com.amazonaws.services.s3.transfer.TransferManager</code> can be easily created in the application
|
||||
code and injected with the pre-configured <code class="literal">com.amazonaws.services.s3.AmazonS3</code> client that is already created
|
||||
with the Spring Cloud AWS resource loader configuration.</p><p>This example shows the use of the <code class="literal">transferManager</code> within an application to upload files from the hard-drive.</p><pre class="programlisting"><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> SimpleResourceLoadingBean {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> AmazonS3 amazonS3;
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> withTransferManager() {
|
||||
TransferManager transferManager = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> TransferManager(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.amazonS3);
|
||||
transferManager.upload(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"myBucket"</span>,<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"filename"</span>,<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> File(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"someFile"</span>));
|
||||
}
|
||||
}</pre></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_searching_resources" href="#_searching_resources"></a>9.4 Searching resources</h2></div></div></div><p>The Spring resource loader also supports collecting resources based on an Ant-style path specification. Spring Cloud AWS
|
||||
offers the same support to resolve resources within a bucket and even throughout buckets. The actual resource loader needs
|
||||
to be wrapped with the Spring Cloud AWS one in order to search for s3 buckets, in case of non s3 bucket the resource loader
|
||||
will fall back to the original one. The next example shows the resource resolution by using different patterns.</p><pre class="programlisting"><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> SimpleResourceLoadingBean {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> ResourcePatternResolver resourcePatternResolver;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</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">void</span> setupResolver(ApplicationContext applicationContext, AmazonS3 amazonS3){
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourcePatternResolver = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> PathMatchingSimpleStorageResourcePatternResolver(amazonS3, applicationContext);
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> resolveAndLoad() <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> IOException {
|
||||
Resource[] allTxtFilesInFolder = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourcePatternResolver.getResources(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://bucket/name/*.txt"</span>);
|
||||
Resource[] allTxtFilesInBucket = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourcePatternResolver.getResources(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://bucket/**/*.txt"</span>);
|
||||
Resource[] allTxtFilesGlobally = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.resourcePatternResolver.getResources(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://**/*.txt"</span>);
|
||||
}
|
||||
}</pre><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Warning"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="images/warning.png"></td><th align="left">Warning</th></tr><tr><td align="left" valign="top"><p>Resolving resources throughout all buckets can be very time consuming depending on the number of buckets a user owns.</p></td></tr></table></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_using_cloudformation_3" href="#_using_cloudformation_3"></a>9.5 Using CloudFormation</h2></div></div></div><p>CloudFormation also allows to create buckets during stack creation. These buckets will typically have a generated name
|
||||
that must be used as the bucket name. In order to allow application developers to define <span class="emphasis"><em>static</em></span> names inside their
|
||||
configuration, Spring Cloud AWS provides support to resolve the generated bucket names.
|
||||
Application developers can use the <code class="literal">org.springframework.cloud.aws.core.env.ResourceIdResolver</code> interface to resolve the
|
||||
physical names that are generated based on the logical names.</p><p>The next example shows a bucket definition inside a CloudFormation stack template. The bucket will be created with a name
|
||||
like <span class="emphasis"><em>integrationteststack-sampleBucket-23qysofs62tc2</em></span></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">"Resources"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"sampleBucket"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">{</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"Type"</span>: <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"AWS::S3::Bucket"</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>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">}</span></pre><p>Application developers can resolve that name and use it to load resources as shown in the next example below.</p><pre class="programlisting"><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> SimpleResourceLoadingBean {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> ResourceLoader loader;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">final</span> ResourceIdResolver idResolver;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> SimpleResourceLoadingBean(ResourceLoader loader, ResourceIdResolver idResolver) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.loader = loader;
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.idResolver = idResolver;
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> resolveAndLoad() {
|
||||
String sampleBucketName = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.idResolver.
|
||||
resolveToPhysicalResourceId(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"sampleBucket"</span>);
|
||||
Resource resource = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.loader.
|
||||
getResource(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"s3://"</span> + sampleBucketName + <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"/test"</span>);
|
||||
}
|
||||
}</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__sending_mails.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">8. Sending mails </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,94 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>8. Sending mails</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi__data_access_with_jdbc.html" title="7. Data Access with JDBC"><link rel="next" href="multi__resource_handling.html" title="9. Resource handling"></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">8. Sending mails</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="multi__data_access_with_jdbc.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__resource_handling.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_sending_mails" href="#_sending_mails"></a>8. Sending mails</h1></div></div></div><p>Spring has a built-in support to send e-mails based on the <a class="link" href="http://www.oracle.com/technetwork/java/javamail/index.html" target="_top">Java Mail API</a>
|
||||
to avoid any static method calls while using the Java Mail API and thus supporting the testability of an application.
|
||||
Spring Cloud AWS supports the <a class="link" href="http://aws.amazon.com/de/ses/" target="_top">Amazon SES</a> as an implementation of the Spring Mail abstraction.</p><p>As a result Spring Cloud AWS users can decide to use the Spring Cloud AWS implementation of the Amazon SES service or
|
||||
use the standard Java Mail API based implementation that sends e-mails via SMTP to Amazon SES.</p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><table border="0" summary="Tip"><tr><td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="images/tip.png"></td><th align="left">Tip</th></tr><tr><td align="left" valign="top"><p>It is preferred to use the Spring Cloud AWS implementation instead of SMTP mainly for performance reasons.
|
||||
Spring Cloud AWS uses one API call to send a mail message, while the SMTP protocol makes multiple requests (EHLO, MAIL FROM, RCPT TO, DATA, QUIT)
|
||||
until it sends an e-mail.</p></td></tr></table></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_the_mail_sender" href="#_configuring_the_mail_sender"></a>8.1 Configuring the mail sender</h2></div></div></div><p>Spring Cloud AWS provides an XML element to configure a Spring <code class="literal">org.springframework.mail.MailSender</code> implementation for the
|
||||
client to be used. The default mail sender works without a Java Mail dependency and is capable of sending messages without
|
||||
attachments as simple mail messages. A configuration with the necessary elements will look like this:</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xmlns:aws-mail</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/mail"</span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">xsi:schemaLocation</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"http://www.springframework.org/schema/cloud/aws/mail
|
||||
http://www.springframework.org/schema/cloud/aws/mail/spring-cloud-aws-mail.xsd"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-credentials></span>
|
||||
..
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></aws-context:context-credentials></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-west-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-mail:mail-sender</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"testSender"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sending_simple_mails" href="#_sending_simple_mails"></a>8.2 Sending simple mails</h2></div></div></div><p>Application developers can inject the <code class="literal">MailSender</code> into their application code and directly send simple text based e-mail
|
||||
messages. The sample below demonstrates the creation of a simple mail message.</p><pre class="programlisting"><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> MailSendingService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> MailSender mailSender;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MailSendingService(MailSender mailSender) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.mailSender = mailSender;
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> sendMailMessage() {
|
||||
SimpleMailMessage simpleMailMessage = <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> SimpleMailMessage();
|
||||
simpleMailMessage.setFrom(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"foo@bar.com"</span>);
|
||||
simpleMailMessage.setTo(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"bar@baz.com"</span>);
|
||||
simpleMailMessage.setSubject(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test subject"</span>);
|
||||
simpleMailMessage.setText(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test content"</span>);
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.mailSender.send(simpleMailMessage);
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_sending_attachments" href="#_sending_attachments"></a>8.3 Sending attachments</h2></div></div></div><p>Sending attachments with e-mail requires MIME messages to be created and sent. In order to create MIME messages,
|
||||
the Java Mail dependency is required and has to be included in the classpath. Spring Cloud AWS will detect the
|
||||
dependency and create a <code class="literal">org.springframework.mail.javamail.JavaMailSender</code> implementation that allows to create and
|
||||
build MIME messages and send them. A dependency configuration for the Java Mail API is the only change in the configuration
|
||||
which is shown below.</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><dependency></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>javax.mail<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>mailapi<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><version></span>1.4.1<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></version></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><exclusions></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-comment"><!-- exclusion because we are running on Java 1.7 that includes the activation API by default--></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><exclusion></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><artifactId></span>activation<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></artifactId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><groupId></span>javax.activation<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></groupId></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></exclusion></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></exclusions></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></dependency></span></pre><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>Even though there is a dependency to the Java Mail API there is still the Amazon SES API used underneath to send mail
|
||||
messages. There is no <a class="link" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp.html" target="_top">SMTP setup</a> required
|
||||
on the Amazon AWS side.</p></td></tr></table></div><p>Sending the mail requires the application developer to use the <code class="literal">JavaMailSender</code> to send an e-mail as shown in the example
|
||||
below.</p><pre class="programlisting"><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> MailSendingService {
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">private</span> JavaMailSender mailSender;
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Autowired</span></em>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> MailSendingService(JavaMailSender mailSender) {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.mailSender = mailSender;
|
||||
}
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">public</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">void</span> sendMailMessage() {
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">this</span>.mailSender.send(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> MimeMessagePreparator() {
|
||||
|
||||
<em><span class="hl-annotation" style="color: gray">@Override</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">void</span> prepare(MimeMessage mimeMessage) <span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">throws</span> Exception {
|
||||
MimeMessageHelper helper =
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-keyword">new</span> MimeMessageHelper(mimeMessage, true, <span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"UTF-8"</span>);
|
||||
helper.addTo(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"foo@bar.com"</span>);
|
||||
helper.setFrom(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"bar@baz.com"</span>);
|
||||
helper.addAttachment(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test.txt"</span>, ...);
|
||||
helper.setSubject(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"test subject with attachment"</span>);
|
||||
helper.setText(<span xmlns:d="http://docbook.org/ns/docbook" class="hl-string">"mime body"</span>, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}</pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_configuring_regions" href="#_configuring_regions"></a>8.4 Configuring regions</h2></div></div></div><p>Amazon SES is not available in all <a class="link" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html" target="_top">regions</a> of the
|
||||
Amazon Web Services cloud. Therefore an application hosted and operated in a region that does not support the mail
|
||||
service will produce an error while using the mail service. Therefore the region must be overridden for the mail
|
||||
sender configuration. The example below shows a typical combination of a region (EU-CENTRAL-1) that does not provide
|
||||
an SES service where the client is overridden to use a valid region (EU-WEST-1).</p><pre class="programlisting"><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><beans</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">...></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute"><aws-context:context-region</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-central-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"> /></span>
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"><aws-mail:mail-sender</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">id</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"testSender"</span> <span xmlns:d="http://docbook.org/ns/docbook" class="hl-attribute">region</span>=<span xmlns:d="http://docbook.org/ns/docbook" class="hl-value">"eu-west-1"</span><span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag">/></span>
|
||||
|
||||
<span xmlns:d="http://docbook.org/ns/docbook" class="hl-tag"></beans></span></pre></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="_authenticating_e_mails" href="#_authenticating_e_mails"></a>8.5 Authenticating e-mails</h2></div></div></div><p>To avoid any spam attacks on the Amazon SES mail service, applications without production access must
|
||||
<a class="link" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html" target="_top">verify</a> each
|
||||
e-mail receiver otherwise the mail sender will throw a <code class="literal">com.amazonaws.services.simpleemail.model.MessageRejectedException</code>.</p><p><a class="link" href="http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html" target="_top">Production access</a> can be requested
|
||||
and will disable the need for mail address verification.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="multi__data_access_with_jdbc.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__resource_handling.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">7. Data Access with JDBC </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 9. Resource handling</td></tr></table></div></body></html>
|
||||
@@ -0,0 +1,18 @@
|
||||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||||
<title>1. Using Amazon Web Services</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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi_pr01.html" title=""><link rel="next" href="multi__basic_setup.html" title="2. Basic setup"></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. Using Amazon Web Services</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__basic_setup.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="_using_amazon_web_services" href="#_using_amazon_web_services"></a>1. Using Amazon Web Services</h1></div></div></div><p>Amazon provides a <a class="link" href="http://aws.amazon.com/sdk-for-java/" target="_top">Java SDK</a> to issue requests for the all services provided by the
|
||||
<a class="link" href="http://aws.amazon.com" target="_top">Amazon Web Service</a> platform. Using the SDK, application developers still have to integrate the
|
||||
SDK into their application with a considerable amount of infrastructure related code. Spring Cloud AWS provides application
|
||||
developers already integrated Spring-based modules to consume services and avoid infrastructure related code as much as possible.
|
||||
The Spring Cloud AWS module provides a module set so that application developers can arrange the dependencies based on
|
||||
their needs for the particular services. The graphic below provides a general overview of all Spring Cloud AWS modules along
|
||||
with the service support for the respective Spring Cloud AWS services.</p><div class="informalfigure"><div class="mediaobject"><img src="images/overview.png" alt="Overview"></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><span class="strong"><strong>Spring Cloud AWS Core</strong></span> is the core module of Spring Cloud AWS providing basic services for security and configuration
|
||||
setup. Developers will not use this module directly but rather through other modules. The core module provides support for
|
||||
cloud based environment configurations providing direct access to the instance based <a class="link" href="http://aws.amazon.com/ec2/" target="_top">EC2</a>
|
||||
metadata and the overall application stack specific <a class="link" href="http://aws.amazon.com/cloudformation/" target="_top">CloudFormation</a> metadata.</li><li class="listitem"><span class="strong"><strong>Spring Cloud AWS Context</strong></span> delivers access to the <a class="link" href="http://aws.amazon.com/s3/" target="_top">Simple Storage Service</a> via the Spring
|
||||
resource loader abstraction. Moreover developers can send e-mails using the <a class="link" href="http://aws.amazon.com/ses/" target="_top">Simple E-Mail Service</a>
|
||||
and the Spring mail abstraction. Further the developers can introduce declarative caching using the Spring caching support
|
||||
and the <a class="link" href="http://aws.amazon.com/elasticache/" target="_top">ElastiCache</a> caching service.</li><li class="listitem"><span class="strong"><strong>Spring Cloud AWS JDBC</strong></span> provides automatic datasource lookup and configuration for the <a class="link" href="http://aws.amazon.com/rds/" target="_top">Relational Database Service</a>
|
||||
which can be used with JDBC or any other support data access technology by Spring.</li><li class="listitem"><span class="strong"><strong>Spring Cloud AWS Messaging</strong></span> enables developers to receive and send messages with the <a class="link" href="http://aws.amazon.com/sqs/" target="_top">Simple Queueing Service</a> for
|
||||
point-to-point communication. Publish-subscribe messaging is supported with the integration of the <a class="link" href="http://aws.amazon.com/sns/" target="_top">Simple Notification Service</a>.</li><li class="listitem"><span class="strong"><strong>Spring Cloud AWS Parameter Store Configuration</strong></span> enables Spring Cloud applications to use the <a class="link" href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html" target="_top">AWS Parameter Store</a>
|
||||
as a Bootstrap Property Source, comparable to the support provided for the Spring Cloud Config Server or Consul’s key-value store.</li></ul></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__basic_setup.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-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 2. Basic setup</td></tr></table></div></body></html>
|
||||
3
spring-cloud-aws/2.0.0.RELEASE/multi/multi_pr01.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<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-aws.html" title="Spring Cloud AWS"><link rel="up" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="prev" href="multi_spring-cloud-aws.html" title="Spring Cloud AWS"><link rel="next" href="multi__using_amazon_web_services.html" title="1. Using Amazon Web Services"></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-aws.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="multi__using_amazon_web_services.html">Next</a></td></tr></table><hr></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a name="d0e28" href="#d0e28"></a></h1></div></div></div><p>Spring Cloud for Amazon Web Services, part of the Spring Cloud umbrella project, eases the integration with hosted Amazon Web Services. It offers a convenient way to interact with AWS provided services using well-known Spring idioms and APIs, such as the messaging or caching API. Developers can build their application around the hosted services without having to care about infrastructure or maintenance.</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-aws/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-aws.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="multi__using_amazon_web_services.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Spring Cloud AWS </td><td width="20%" align="center"><a accesskey="h" href="multi_spring-cloud-aws.html">Home</a></td><td width="40%" align="right" valign="top"> 1. Using Amazon Web Services</td></tr></table></div></body></html>
|
||||
35
spring-cloud-aws/2.0.0.RELEASE/single/css/highlight.css
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
code highlight CSS resemblign the Eclipse IDE default color schema
|
||||
@author Costin Leau
|
||||
*/
|
||||
|
||||
.hl-keyword {
|
||||
color: #7F0055;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hl-comment {
|
||||
color: #3F5F5F;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-multiline-comment {
|
||||
color: #3F5FBF;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hl-tag {
|
||||
color: #3F7F7F;
|
||||
}
|
||||
|
||||
.hl-attribute {
|
||||
color: #7F007F;
|
||||
}
|
||||
|
||||
.hl-value {
|
||||
color: #2A00FF;
|
||||
}
|
||||
|
||||
.hl-string {
|
||||
color: #2A00FF;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body.firstpage {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: none;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@IMPORT url("manual.css");
|
||||
|
||||
body {
|
||||
background: url("../images/background.png") no-repeat center top;
|
||||
}
|
||||
|
||||
344
spring-cloud-aws/2.0.0.RELEASE/single/css/manual.css
Normal file
@@ -0,0 +1,344 @@
|
||||
@IMPORT url("highlight.css");
|
||||
|
||||
html {
|
||||
padding: 0pt;
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #333333;
|
||||
margin: 15px 30px;
|
||||
font-family: Helvetica, Arial, Freesans, Clean, Sans-serif;
|
||||
line-height: 1.6;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
code {
|
||||
font-size: 16px;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
:not(a)>code {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
:not(pre)>code {
|
||||
background-color: #F2F2F2;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 4px;
|
||||
padding: 1px 3px 0;
|
||||
text-shadow: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
body>*:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
div {
|
||||
margin: 0pt;
|
||||
}
|
||||
|
||||
hr {
|
||||
border: 1px solid #CCCCCC;
|
||||
background: #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h2,h3,h4,h5,h6 {
|
||||
color: #000000;
|
||||
cursor: text;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1,h2,h3 {
|
||||
margin: 40px 0 10px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 70px 0 30px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
div.part h1 {
|
||||
border-top: 1px dotted #CCCCCC;
|
||||
}
|
||||
|
||||
h1,h1 code {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
h2,h2 code {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
h3,h3 code {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
h4,h1 code,h5,h5 code,h6,h6 code {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
div.book,div.chapter,div.appendix,div.part,div.preface {
|
||||
min-width: 300px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
p.releaseinfo {
|
||||
font-weight: bold;
|
||||
margin-bottom: 40px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
div.authorgroup {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
p.copyright {
|
||||
line-height: 1;
|
||||
margin-bottom: -5px;
|
||||
}
|
||||
|
||||
.legalnotice p {
|
||||
font-style: italic;
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.titlepage+p,div.titlepage+p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
pre {
|
||||
line-height: 1.0;
|
||||
color: black;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #4183C4;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 15px 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
ul,ol {
|
||||
padding-left: 30px;
|
||||
}
|
||||
|
||||
li p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.table {
|
||||
margin: 1em;
|
||||
padding: 0.5em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
div.table table,div.informaltable table {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.table td {
|
||||
padding-left: 7px;
|
||||
padding-right: 7px;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
line-height: 1.4;
|
||||
padding: 0 20px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
}
|
||||
|
||||
.sidebar p.title {
|
||||
color: #6D180B;
|
||||
}
|
||||
|
||||
pre.programlisting,pre.screen {
|
||||
font-size: 15px;
|
||||
padding: 6px 10px;
|
||||
background-color: #F8F8F8;
|
||||
border: 1px solid #CCCCCC;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
clear: both;
|
||||
overflow: auto;
|
||||
line-height: 1.4;
|
||||
font-family: Consolas, "Liberation Mono", Courier, monospace;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
border: 1px solid #DDDDDD !important;
|
||||
border-radius: 4px !important;
|
||||
border-collapse: separate !important;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
table thead {
|
||||
background: #F5F5F5;
|
||||
}
|
||||
|
||||
table tr {
|
||||
border: none;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
table th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
table th,table td {
|
||||
border: none !important;
|
||||
padding: 6px 13px;
|
||||
}
|
||||
|
||||
table tr:nth-child(2n) {
|
||||
background-color: #F8F8F8;
|
||||
}
|
||||
|
||||
td p {
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
div.table-contents td p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important *,div.note *,div.tip *,div.warning *,div.navheader *,div.navfooter *,div.calloutlist *
|
||||
{
|
||||
border: none !important;
|
||||
background: none !important;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.important p,div.note p,div.tip p,div.warning p {
|
||||
color: #6F6F6F;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
div.important code,div.note code,div.tip code,div.warning code {
|
||||
background-color: #F2F2F2 !important;
|
||||
border: 1px solid #CCCCCC !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 1px 3px 0 !important;
|
||||
text-shadow: none !important;
|
||||
white-space: nowrap !important;
|
||||
}
|
||||
|
||||
.note th,.tip th,.warning th {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.note tr:first-child td,.tip tr:first-child td,.warning tr:first-child td
|
||||
{
|
||||
border-right: 1px solid #CCCCCC !important;
|
||||
padding-top: 10px;
|
||||
}
|
||||
|
||||
div.calloutlist p,div.calloutlist td {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
div.calloutlist>table>tbody>tr>td:first-child {
|
||||
padding-left: 10px;
|
||||
width: 30px !important;
|
||||
}
|
||||
|
||||
div.important,div.note,div.tip,div.warning {
|
||||
margin-left: 0px !important;
|
||||
margin-right: 20px !important;
|
||||
margin-top: 20px;
|
||||
margin-bottom: 20px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
div.toc {
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
dl,dt {
|
||||
margin-top: 1px;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
div.toc>dl>dt {
|
||||
font-size: 32px;
|
||||
font-weight: bold;
|
||||
margin: 30px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dt {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
margin: 20px 0 10px 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
div.toc>dl>dd>dl>dd>dl>dt {
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
margin: 10px 0 0 0;
|
||||
}
|
||||
|
||||
tbody.footnotes * {
|
||||
border: none !important;
|
||||
}
|
||||
|
||||
div.footnote p {
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
div.footnote p sup {
|
||||
margin-right: 6px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.navheader {
|
||||
border-bottom: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
div.navfooter {
|
||||
border-top: 1px solid #CCCCCC;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-left: -1em;
|
||||
padding-left: 1em;
|
||||
}
|
||||
|
||||
.title>a {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
display: block;
|
||||
font-size: 0.85em;
|
||||
margin-top: 0.05em;
|
||||
margin-left: -1em;
|
||||
vertical-align: text-top;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.title>a:before {
|
||||
content: "\00A7";
|
||||
}
|
||||
|
||||
.title:hover>a,.title>a:hover,.title:hover>a:hover {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.title:focus>a,.title>a:focus,.title:focus>a:focus {
|
||||
outline: 0;
|
||||
}
|
||||
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/background.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/callouts/1.png
Normal file
|
After Width: | Height: | Size: 329 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/callouts/2.png
Normal file
|
After Width: | Height: | Size: 353 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/callouts/3.png
Normal file
|
After Width: | Height: | Size: 350 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/caution.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/important.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/logo.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/note.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/tip.png
Normal file
|
After Width: | Height: | Size: 931 B |
BIN
spring-cloud-aws/2.0.0.RELEASE/single/images/warning.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |