Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up of UIs and logging output

  • Loading branch information...
commit 77cc7f480b37c9f8d6f716e59ce20bdcbceee22a 1 parent 865b97d
@ryanbrainard ryanbrainard authored
View
4 common/src/main/java/com/heroku/devcenter/BigOperation.java
@@ -3,7 +3,9 @@
import java.io.Serializable;
/**
- * @author Ryan Brainard
+ * A model class for a big, imaginary, expensive operation
+ * that a user submits via the web, but is processed async
+ * by a worker.
*/
public class BigOperation implements Serializable {
View
1  web/pom.xml
@@ -55,6 +55,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
View
20 ...om/heroku/devcenter/RabbitController.java → .../devcenter/BigOperationWebController.java
@@ -9,10 +9,17 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import java.util.Map;
+
+/**
+ * Web controller for receiving BigOperations from users
+ * and sending them to RabbitMQ for async processing by BigOperationWorker
+ */
@Controller
@RequestMapping("/rabbit")
-public class RabbitController {
+public class BigOperationWebController {
+ // load RabbitMQ configuration provided by Spring
private final ApplicationContext rabbitConfig = new AnnotationConfigApplicationContext(RabbitConfiguration.class);
private final AmqpTemplate amqpTemplate = rabbitConfig.getBean(AmqpTemplate.class);
private final Queue rabbitQueue = rabbitConfig.getBean(Queue.class);
@@ -24,14 +31,17 @@ public BigOperation newBigOp() {
@RequestMapping()
public String display() {
- return "rabbitForm";
+ return "bigOpSubmissionForm";
}
@RequestMapping(method = RequestMethod.POST)
- public String process(@ModelAttribute("bigOp") BigOperation bigOp) {
+ public String process(@ModelAttribute("bigOp") BigOperation bigOp, Map<String,Object> map) {
+ // Receives the bigOp from the form submission, converts to a message, and sends to RabbitMQ.
amqpTemplate.convertAndSend(rabbitQueue.getName(), bigOp);
- System.out.println("Sent BigOperation to RabbitMQ on queue: " + bigOp.getName());
+ System.out.println("Sent to RabbitMQ: " + bigOp);
- return "rabbitConfirmation";
+ // Send the bigOp back to the confirmation page for displaying details in view
+ map.put("bigOp", bigOp);
+ return "bigOpReceivedConfirmation";
}
}
View
31 web/src/main/webapp/WEB-INF/jsp/bigOpReceivedConfirmation.jsp
@@ -0,0 +1,31 @@
+<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<jsp:include page="header.jsp"/>
+<div class="row">
+ <div class="span8 offset2">
+ <div class="page-header">
+ <h1>Big Operation Submitted</h1>
+ </div>
+
+ <div>
+ <p>
+ Your request was received and has been sent for processing.
+ </p>
+ <p>
+ If you haven't already done so, be sure to scale up one or more worker dynos and tail the logs:
+ </p>
+ <p>
+ <code>$ heroku scale worker=1</code><br/>
+ <code>$ heroku logs --tail</code>
+ </p>
+ <p>
+ In your logs you should see that the operation passed from the <code>web</code> dyno
+ to one of your <code>worker</code> dynos, which should look something like this:
+ </p>
+ <p>
+ <code>16:50:29 web.1 | Sent to RabbitMQ: BigOperation{name='${bigOp.name}'}</code><br/>
+ <code>16:50:30 worker.1 | Received from RabbitMQ: BigOperation{name='${bigOp.name}'}</code>
+ </p>
+ </div>
+ </div>
+</div>
+<jsp:include page="footer.jsp"/>
View
36 web/src/main/webapp/WEB-INF/jsp/bigOpSubmissionForm.jsp
@@ -0,0 +1,36 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
+<jsp:include page="header.jsp"/>
+<div class="row">
+ <div class="span8 offset2">
+ <div class="page-header">
+ <h1>Big Operation Submission Form</h1>
+ </div>
+ <div>
+ <p>
+ This is a form to submit a imaginary operation that might take a long time be processed in a web request,
+ so is processed asynchronously by one or more worker dynos.
+ First, make sure you have a one or more worker dynos running:
+ </p>
+ <p>
+ <code>$ heroku scale worker=1</code>
+ </p>
+ <p>
+ Next, start tailing the logs so you can see operation being passed from
+ the <code>web</code> dyno to one of your <code>worker</code> dynos.
+ </p>
+ <p>
+ <code>$ heroku logs --tail</code>
+ </p>
+ <p>
+ With the logs open, give your operation a name and submit the form below:
+ </p>
+ </div>
+
+ <form:form method="post" modelAttribute="bigOp" class="well form-inline">
+ <label>Name: <form:input path="name"/></label>
+ <input type="submit" class="btn btn-primary">
+ </form:form>
+ </div>
+</div>
+<jsp:include page="footer.jsp"/>
View
4 web/src/main/webapp/WEB-INF/jsp/header.jsp
@@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
- <title>Spring MVC Template for Salesforce</title>
+ <title>Java Web-Worker Template</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -30,7 +30,7 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
- <a href="/" class="brand">Salesforce Spring MVC Template</a>
+ <a href="/" class="brand">Java Web-Worker Template</a>
<a href="/" class="brand" id="heroku">by <strong>heroku</strong></a>
</div>
</div>
View
16 web/src/main/webapp/WEB-INF/jsp/rabbitConfirmation.jsp
@@ -1,16 +0,0 @@
-<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-<jsp:include page="header.jsp"/>
-<div class="row">
- <div class="span8 offset2">
- <div class="page-header">
- <h1>Rabbit Form</h1>
- </div>
-
- <c:if test="${error != null}">
- <div class="alert">${error}</div>
- </c:if>
-
- Thanks!
- </div>
-</div>
-<jsp:include page="footer.jsp"/>
View
23 web/src/main/webapp/WEB-INF/jsp/rabbitForm.jsp
@@ -1,23 +0,0 @@
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
-<jsp:include page="header.jsp"/>
-<div class="row">
- <div class="span8 offset2">
- <div class="page-header">
- <h1>Rabbit Form</h1>
- </div>
-
- <c:if test="${error != null}">
- <div class="alert">${error}</div>
- </c:if>
-
- <form:form method="post" modelAttribute="bigOp">
- <label>Name: <form:input path="name"/></label>
-
- <div class="btn-group">
- <input type="submit" class="btn btn-primary">
- </div>
- </form:form>
- </div>
-</div>
-<jsp:include page="footer.jsp"/>
View
17 web/src/main/webapp/index.jsp
@@ -3,7 +3,7 @@
<html>
<head>
<meta charset="utf-8">
- <title>Spring MVC Template for Salesforce</title>
+ <title>Java Web-Worker Template</title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -56,7 +56,7 @@
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
- <a href="/" class="brand">Spring MVC and Hibernate Template</a>
+ <a href="/" class="brand">Java Web-Worker Template</a>
<!--
IMPORTANT:
This is Heroku specific markup. Remove to customize.
@@ -73,13 +73,14 @@
<h1 class="alert alert-success">Your app is ready!</h1>
<div class="page-header">
- <h1>Get started with your Spring MVC Application for Salesforce</h1>
+ <h1>Get started with your Java Web-Worker Template</h1>
</div>
<div style="margin-bottom: 20px">
- This is a template for a Spring MVC web application to work with data from Salesforce.
- The sample code is a dynamic CRUD application that allows users to create, read, edit, and delete.
- To try it out go to the <a href="/sfdc/sobjects">My Objects</a> page. Then use Eclipse or the Command Line to deploy some changes.
+ This is a template for a Java web app that sends expensive operations to a message queue for asynchronous processing by one or more worker dynos.
+ The sample code uses the <a href="http://www.springsource.org/spring-amqp">Spring AMPQ</a> library along with the
+ Heroku <a href="https://addons.heroku.com/rabbitmq">RabbitMQ add-on</a>.
+ To try it out go to the <a href="/spring/rabbit">Big Operation Submission Form</a>. Then use Eclipse or the Command Line to deploy some changes.
</div>
<ul id="tab" class="nav nav-tabs">
@@ -244,7 +245,7 @@
<div class="hero-unit">
<h1>Done!</h1>
<p>You've just cloned, modified, and deployed a brand new app.</p>
- <a href="/sfdc/sobjects" class="btn btn-primary btn-large">See your changes</a>
+ <a href="/spring/rabbit" class="btn btn-primary btn-large">See your changes</a>
<p style="margin-top: 20px">Learn more at the
<a href="http://devcenter.heroku.com/categories/java">Heroku Dev Center</a></p>
@@ -304,7 +305,7 @@ Authentication successful.</pre>
<div class="hero-unit">
<h1>Done!</h1>
<p>You've just cloned, modified, and deployed a brand new app.</p>
- <a href="/sfdc/sobjects" class="btn btn-primary btn-large">See your changes</a>
+ <a href="/spring/rabbit" class="btn btn-primary btn-large">See your changes</a>
<p style="margin-top: 20px">Learn more at the
<a href="http://devcenter.heroku.com/categories/java">Heroku Dev Center</a></p>
View
2  worker/pom.xml
@@ -29,7 +29,7 @@
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
- <mainClass>com.heroku.devcenter.RabbitReceiver</mainClass>
+ <mainClass>com.heroku.devcenter.BigOperationWorker</mainClass>
<name>worker</name>
</program>
</programs>
View
10 .../com/heroku/devcenter/RabbitReceiver.java → .../heroku/devcenter/BigOperationWorker.java
@@ -11,7 +11,10 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.util.ErrorHandler;
-public class RabbitReceiver {
+/**
+ * Worker for receiving and processing BigOperations asynchronously.
+ */
+public class BigOperationWorker {
public static void main(String[] args) {
final ApplicationContext rabbitConfig = new AnnotationConfigApplicationContext(RabbitConfiguration.class);
@@ -29,7 +32,7 @@ public static void main(String[] args) {
listenerContainer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
final BigOperation bigOp = (BigOperation) messageConverter.fromMessage(message);
- System.out.println("Received Big Operation: " + bigOp.getName());
+ System.out.println("Received from RabbitMQ: " + bigOp);
}
});
@@ -44,12 +47,13 @@ public void handleError(Throwable t) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
- System.out.println("Shutting down RabbitReceiver");
+ System.out.println("Shutting down BigOperationWorker");
listenerContainer.shutdown();
}
});
// start up the listener. this will block until JVM is killed.
listenerContainer.start();
+ System.out.println("BigOperationWorker started");
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.