Skip to content

Commit

Permalink
Add rabbitmq example
Browse files Browse the repository at this point in the history
  • Loading branch information
kchrusciel committed Oct 15, 2017
1 parent 1691c25 commit e01cbf0
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spring-boot-rabbitmq-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
2 changes: 2 additions & 0 deletions spring-boot-rabbitmq-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Spring Boot RabbitMQ integration example
This repository contains Spring Boot RabbitMQ integration example
59 changes: 59 additions & 0 deletions spring-boot-rabbitmq-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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>pl.codecouple</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>demo</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pl.codecouple;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package pl.codecouple.consumer;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
* Created by CodeCouple.pl
*/
@Component
class QueueConsumer {

@RabbitListener(queues = "${queue.name}")
private void reader(String text){
System.out.println("Consumer: " + text);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.codecouple.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* Created by CodeCouple.pl
*/
@RestController("/queue")
class QueueProducer {

@Value("${queue.name}")
private String queueName;

@Autowired
RabbitTemplate queueSender;

@GetMapping
String sendToQueue(@RequestParam(value = "message", defaultValue = "CodeCouple.pl") String message){
queueSender.convertAndSend(queueName, message);
return String.format("Message %s sent! See logs...", message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#RabbitMQ Host
spring.rabbitmq.host=192.168.99.100
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
#Application Port
server.port=8081
#Queue
queue.name=code.couple.queue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pl.codecouple;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {

@Test
public void contextLoads() {
}

}

0 comments on commit e01cbf0

Please sign in to comment.