Book Image

Learning Spring Boot

By : Greg L. Turnquist
Book Image

Learning Spring Boot

By: Greg L. Turnquist

Overview of this book

<p>This practical, accessible guide helps you get up and running fast with Spring Boot. This book starts by crafting a Spring MVC application using the Spring stack on top of Apache Tomcat, with little configuration on from your end. You will also learn how to write both JUnit and Spock test cases. Then, you'll pull back the curtain and see how Spring Boot works by using Spring Messaging (JMS and AMQP) as well as creating custom metrics, custom information, and custom CLI commands aimed at production environments. In the last two chapters, you'll see how Spring Boot supports everyday situations we all deal with. You will learn how to create multiple configurations inside your app that can interact with different data stores.</p> <p>By the end of the book, you'll have a good understanding of how Spring Boot works, how it manages low-level infrastructure, and how to start out production-grade apps with built-in support tools as well as custom ones.</p>
Table of Contents (13 chapters)
Learning Spring Boot
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a JMS-based publisher/subscriber app


To dig in and see how to debug an application, let's put together something simple: an app that monitors incoming messages from the network. These messages can indicate different levels of network degradation or recovery as reported by various devices.

For a pretty basic JMS-based app that runs on top of ActiveMQ, we can use the following build.gradle build file:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.1.6.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

jar {
    baseName = 'network-monitor'
    version =  '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

// tag::clean[]
clean {
    delete "activemq-data"
}
// end::clean[]

dependencies {
    compile("org.springframework.boot:spring-boot-starter")
    compile("org.springframework:spring-jms")
    compile...