Permalink
Browse files

Initial modularization into worker and web

  • Loading branch information...
1 parent a5820a0 commit 9210972f6307bb056b763ae22fd1f3c5d92256d8 @ryanbrainard ryanbrainard committed Jun 5, 2012
Showing with 1,148 additions and 134 deletions.
  1. +2 −0 .gitignore
  2. +2 −2 Procfile
  3. +1 −1 README.md
  4. +30 −0 common/pom.xml
  5. +13 −4 ...u/devcenter/RabbitFactoryUtil.java → common/src/main/java/com/heroku/devcenter/RabbitFactory.java
  6. +18 −52 pom.xml
  7. +0 −37 src/main/java/com/heroku/devcenter/PojoReceiver.java
  8. +0 −32 src/main/java/com/heroku/devcenter/PojoSender.java
  9. +93 −0 web/pom.xml
  10. +7 −3 ...heroku/devcenter/SpringSender.java → web/src/main/java/com/heroku/devcenter/RabbitController.java
  11. +46 −0 web/src/main/resources/applicationContext.xml
  12. +40 −0 web/src/main/webapp/WEB-INF/jsp/editSObjectRecord.jsp
  13. +4 −0 web/src/main/webapp/WEB-INF/jsp/footer.jsp
  14. +39 −0 web/src/main/webapp/WEB-INF/jsp/header.jsp
  15. +35 −0 web/src/main/webapp/WEB-INF/web.xml
  16. +324 −0 web/src/main/webapp/index.jsp
  17. +9 −0 web/src/main/webapp/resources/css/bootstrap-responsive.min.css
  18. +9 −0 web/src/main/webapp/resources/css/bootstrap.min.css
  19. +31 −0 web/src/main/webapp/resources/css/heroku.css
  20. BIN web/src/main/webapp/resources/img/glyphicons-halflings-white.png
  21. BIN web/src/main/webapp/resources/img/glyphicons-halflings.png
  22. +218 −0 web/src/main/webapp/resources/js/bootstrap-modal.js
  23. +135 −0 web/src/main/webapp/resources/js/bootstrap-tab.js
  24. +6 −0 web/src/main/webapp/resources/js/bootstrap.min.js
  25. +30 −0 web/src/main/webapp/resources/js/google-code-prettify/prettify.js
  26. +4 −0 web/src/main/webapp/resources/js/jquery-1.7.1.min.js
  27. +48 −0 worker/pom.xml
  28. +3 −2 { → worker}/src/main/java/com/heroku/devcenter/SpringReceiver.java
  29. +1 −1 { → worker}/src/main/resources/applicationContext.xml
View
@@ -1,3 +1,5 @@
+.idea
+*.iml
.classpath
.settings/
target
View
@@ -1,2 +1,2 @@
-sender: sh target/bin/sender
-receiver: sh target/bin/receiver
+web: java $JAVA_OPTS_WEB -jar web/target/dependency/webapp-runner.jar --port $PORT web/target/*.war
+receiver: sh worker/target/bin/receiver
View
@@ -83,7 +83,7 @@ Application context XML to configure the rabbit template:
<bean id="cf" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<!-- This constructor arg utilizes the RabbitFactoryUtil class shown in the java example above -->
- <constructor-arg><value>#{ T(com.heroku.devcenter.RabbitFactoryUtil).getConnectionFactory()}</value></constructor-arg>
+ <constructor-arg><value>#{ T(com.heroku.devcenter.RabbitFactory).getConnectionFactory()}</value></constructor-arg>
</bean>
<rabbit:queue id="sample-queue" durable="true" auto-delete="false" exclusive="false" name="sample-queue"/>
View
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.heroku.devcenter.webworker</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>common</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.rabbitmq</groupId>
+ <artifactId>amqp-client</artifactId>
+ <version>2.7.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.amqp</groupId>
+ <artifactId>spring-rabbit</artifactId>
+ <version>1.0.0.RELEASE</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
@@ -1,17 +1,18 @@
package com.heroku.devcenter;
-import static java.lang.System.getenv;
+import com.rabbitmq.client.ConnectionFactory;
+
import java.net.URI;
import java.net.URISyntaxException;
-import com.rabbitmq.client.ConnectionFactory;
+import static java.lang.System.getenv;
-public class RabbitFactoryUtil {
+public class RabbitFactory {
public static ConnectionFactory getConnectionFactory() throws URISyntaxException {
ConnectionFactory factory = new ConnectionFactory();
- URI uri = new URI(getenv("RABBITMQ_URL"));
+ URI uri = new URI(getEnvOrThrow("RABBITMQ_URL"));
factory.setUsername(uri.getUserInfo().split(":")[0]);
factory.setPassword(uri.getUserInfo().split(":")[1]);
factory.setHost(uri.getHost());
@@ -21,4 +22,12 @@ public static ConnectionFactory getConnectionFactory() throws URISyntaxException
return factory;
}
+ private static String getEnvOrThrow(String name) {
+ final String env = getenv(name);
+ if (env == null) {
+ throw new IllegalStateException("Environment variable [" + name + "] is not set.");
+ }
+ return env;
+ }
+
}
View
70 pom.xml
@@ -1,52 +1,18 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.heroku.devcenter</groupId>
- <artifactId>rabbitMqSample</artifactId>
- <version>0.0.1-SNAPSHOT</version>
-
- <dependencies>
- <dependency>
- <groupId>com.rabbitmq</groupId>
- <artifactId>amqp-client</artifactId>
- <version>2.7.0</version>
- </dependency>
-
- <!-- Required only if using Spring -->
- <dependency>
- <groupId>org.springframework.amqp</groupId>
- <artifactId>spring-rabbit</artifactId>
- <version>1.0.0.RELEASE</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>appassembler-maven-plugin</artifactId>
- <version>1.1.1</version>
- <configuration>
- <assembleDirectory>target</assembleDirectory>
- <programs>
- <program>
- <mainClass>com.heroku.devcenter.PojoSender</mainClass>
- <name>sender</name>
- </program>
- <program>
- <mainClass>com.heroku.devcenter.PojoReceiver</mainClass>
- <name>receiver</name>
- </program>
- </programs>
- </configuration>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>assemble</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.heroku.devcenter.webworker</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>common</module>
+ <module>web</module>
+ <module>worker</module>
+ </modules>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
@@ -1,37 +0,0 @@
-package com.heroku.devcenter;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import com.rabbitmq.client.ConnectionFactory;
-import com.rabbitmq.client.GetResponse;
-import com.rabbitmq.client.QueueingConsumer;
-
-public class PojoReceiver {
-
- public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException {
- ConnectionFactory factory = RabbitFactoryUtil.getConnectionFactory();
- Connection connection = factory.newConnection();
- Channel channel = connection.createChannel();
- String exchangeName = "sample-exchange";
- String queueName = "sample-queue";
- String routingKey = "sample-key";
- channel.exchangeDeclare(exchangeName, "direct", true);
- channel.queueDeclare(queueName, true, false, false, null);
- channel.queueBind(queueName, exchangeName, routingKey);
- QueueingConsumer consumer = new QueueingConsumer(channel);
- channel.basicConsume(queueName, true, consumer);
-
- while (true) {
- System.out.println("Waiting for message...");
- //consumer.nextDelivery will block until it receives a message
- QueueingConsumer.Delivery delivery = consumer.nextDelivery();
- if (delivery != null) {
- System.out.println("Recieved:->" + new String(delivery.getBody(), "UTF-8"));
- }
- }
-
- }
-}
@@ -1,32 +0,0 @@
-package com.heroku.devcenter;
-
-import java.io.IOException;
-import java.net.URISyntaxException;
-
-import com.rabbitmq.client.Channel;
-import com.rabbitmq.client.Connection;
-import com.rabbitmq.client.ConnectionFactory;
-
-public class PojoSender {
-
- public static void main(String[] args) throws IOException, InterruptedException, URISyntaxException {
- ConnectionFactory factory = RabbitFactoryUtil.getConnectionFactory();
- Connection connection = factory.newConnection();
- Channel channel = connection.createChannel();
- String exchangeName = "sample-exchange";
- String queueName = "sample-queue";
- String routingKey = "sample-key";
- channel.exchangeDeclare(exchangeName, "direct", true);
- channel.queueDeclare(queueName, true, false, false, null);
- channel.queueBind(queueName, exchangeName, routingKey);
-
- while (true) {
- String msg = "Sent at:" + System.currentTimeMillis();
- byte[] body = msg.getBytes("UTF-8");
- channel.basicPublish(exchangeName, routingKey, null, body);
- System.out.println("Sent:->" + msg);
- Thread.sleep(1000);
- }
-
- }
-}
View
@@ -0,0 +1,93 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>com.heroku.devcenter.webworker</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>web</artifactId>
+ <packaging>war</packaging>
+
+ <dependencies>
+ <dependency>
+ <artifactId>common</artifactId>
+ <groupId>com.heroku.devcenter.webworker</groupId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.amqp</groupId>
+ <artifactId>spring-rabbit</artifactId>
+ <version>1.0.0.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>3.1.1.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>taglibs</groupId>
+ <artifactId>standard</artifactId>
+ <version>1.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>com.github.jsimone</groupId>
+ <artifactId>webapp-runner</artifactId>
+ <version>7.0.27.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>com.github.jsimone</groupId>
+ <artifactId>webapp-runner</artifactId>
+ <version>7.0.27.1</version>
+ <destFileName>webapp-runner.jar</destFileName>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
@@ -1,13 +1,17 @@
package com.heroku.devcenter;
-import java.io.UnsupportedEncodingException;
-
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.io.UnsupportedEncodingException;
-public class SpringSender {
+@Controller
+@RequestMapping("/pdf")
+public class RabbitController {
public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xmlns:rabbit="http://www.springframework.org/schema/rabbit"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
+ http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
+
+ <context:annotation-config />
+ <context:component-scan base-package="com.heroku.devcenter" />
+
+ <mvc:annotation-driven/>
+
+ <bean id="cf" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
+ <constructor-arg><value>#{ T(com.heroku.devcenter.RabbitFactory).getConnectionFactory()}</value></constructor-arg>
+ </bean>
+
+ <rabbit:queue id="sample-queue" durable="true" auto-delete="false" exclusive="false" name="sample-queue"/>
+
+ <rabbit:direct-exchange name="sample-exchange" durable="true" auto-delete="false" id="sample-exchange">
+ <rabbit:bindings>
+ <rabbit:binding queue="sample-queue" key="sample-key"/>
+ </rabbit:bindings>
+ </rabbit:direct-exchange>
+
+ <bean id="template" class="org.springframework.amqp.rabbit.core.RabbitTemplate">
+ <property name="connectionFactory" ref="cf"/>
+ <property name="exchange" value="sample-exchange"/>
+ <property name="queue" value="sample-queue"/>
+ <property name="routingKey" value="sample-key"/>
+ </bean>
+
+ <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+ <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
+ <property name="prefix" value="/WEB-INF/jsp/" />
+ <property name="suffix" value=".jsp" />
+ <property name="redirectHttp10Compatible" value="false" />
+ </bean>
+
+ <!--suppress SpringModelInspection -->
+ <mvc:resources mapping="/resources/**" location="/resources/" />
+
+</beans>
Oops, something went wrong.

0 comments on commit 9210972

Please sign in to comment.