Commit 1057f561 authored by David Dupplaw's avatar David Dupplaw

Initial commit

parents
target
.idea
FROM java:8-jre
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD ["java", "-jar", "target/service-under-test-1.0.0.jar"]
\ No newline at end of file
<?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>
<groupId>uk.me.dupplaw.david</groupId>
<artifactId>service-under-test</artifactId>
<version>1.0.0</version>
<name>service-under-test</name>
<url>http://david.dupplaw.me.uk/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>5.7.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>
uk.me.dupplaw.david.integration.ServiceUnderTest
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package uk.me.dupplaw.david.integration;
import javax.jms.*;
public class MessageHandler implements MessageListener {
private final MessageProducer producer;
private final Session session;
public MessageHandler(Session session, Destination destination ) throws JMSException {
this.session = session;
this.producer = session.createProducer(destination);
}
@Override
public void onMessage(Message message) {
try {
System.out.println(" - Got message: "+message );
TextMessage newMessage = session.createTextMessage("Message was: "+message.getStringProperty("message"));
producer.send(newMessage);
} catch (JMSException e) {
e.printStackTrace();
}
}
}
package uk.me.dupplaw.david.integration;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;
public class ServiceUnderTest
{
public static void main(String[] args) throws JMSException, InterruptedException {
final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
final Connection connection = connectionFactory.createConnection();
System.out.println("Connecting to ActiveMQ...");
connection.start();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue source = session.createQueue("input-queue");
final Queue destination = session.createQueue("output-queue");
final MessageConsumer consumer = session.createConsumer(source);
consumer.setMessageListener( new MessageHandler(session, destination) );
System.out.println("Waiting for messages on "+source+"...");
while(true) Thread.sleep(50);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment