Skip to content

Commit

Permalink
Initial modularization into worker and web
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrainard committed Jun 5, 2012
1 parent a5820a0 commit 9210972
Show file tree
Hide file tree
Showing 29 changed files with 1,148 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,5 @@
.idea
*.iml
.classpath
.settings/
target
Expand Down
4 changes: 2 additions & 2 deletions Procfile
@@ -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
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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"/>
Expand Down
30 changes: 30 additions & 0 deletions common/pom.xml
@@ -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());
Expand All @@ -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;
}

}
70 changes: 18 additions & 52 deletions 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>
37 changes: 0 additions & 37 deletions src/main/java/com/heroku/devcenter/PojoReceiver.java

This file was deleted.

32 changes: 0 additions & 32 deletions src/main/java/com/heroku/devcenter/PojoSender.java

This file was deleted.

93 changes: 93 additions & 0 deletions web/pom.xml
@@ -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");
Expand Down
46 changes: 46 additions & 0 deletions web/src/main/resources/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>

0 comments on commit 9210972

Please sign in to comment.