BAEL-2688 Remove spring-amqp-simple project
This commit is contained in:
parent
76c0918b49
commit
168cd4a0a4
@ -1,2 +0,0 @@
|
||||
### Relevant Articles:
|
||||
- [RabbitMQ Message Dispatching with Spring AMQP](http://www.baeldung.com/rabbitmq-spring-amqp)
|
@ -1,28 +0,0 @@
|
||||
<?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>com.baeldung</groupId>
|
||||
<artifactId>spring-amqp-simple</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>spring-amqp-simple</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<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>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,17 +0,0 @@
|
||||
package com.baeldung.springamqpsimple;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MessageConsumer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
|
||||
|
||||
@RabbitListener(queues = {SpringAmqpConfig.queueName})
|
||||
public void receiveMessage(String message) {
|
||||
logger.info("Received Message: " + message);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.baeldung.springamqpsimple;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Controller
|
||||
public class MessageController {
|
||||
|
||||
private final MessageProducer messageProducer;
|
||||
|
||||
@Autowired
|
||||
public MessageController(MessageProducer messageProducer) {
|
||||
this.messageProducer = messageProducer;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/messages", method= RequestMethod.POST)
|
||||
@ResponseStatus(value= HttpStatus.CREATED)
|
||||
public void sendMessage(@RequestBody String message) {
|
||||
messageProducer.sendMessage(message);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.baeldung.springamqpsimple;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MessageProducer {
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
public MessageProducer(RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
public void sendMessage(String message) {
|
||||
rabbitTemplate.convertAndSend(SpringAmqpConfig.queueName, message);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.baeldung.springamqpsimple;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringAmqpApplication {
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(SpringAmqpApplication.class, args);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.baeldung.springamqpsimple;
|
||||
|
||||
import org.springframework.amqp.core.Binding;
|
||||
import org.springframework.amqp.core.BindingBuilder;
|
||||
import org.springframework.amqp.core.DirectExchange;
|
||||
import org.springframework.amqp.core.Exchange;
|
||||
import org.springframework.amqp.core.Queue;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@Configuration
|
||||
public class SpringAmqpConfig {
|
||||
|
||||
public final static String queueName = "com.baeldung.spring-amqp-simple.queue";
|
||||
public final static String exchangeName = "com.baeldung.spring-amqp-simple.exchange";
|
||||
|
||||
@Bean
|
||||
Queue queue() {
|
||||
return new Queue(queueName, false);
|
||||
}
|
||||
|
||||
@Bean
|
||||
Exchange exchange() {
|
||||
return new DirectExchange(exchangeName);
|
||||
}
|
||||
|
||||
@Bean
|
||||
Binding binding(Queue queue, DirectExchange exchange) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(queueName);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SimpleMessageListenerContainer springAmqpContainer(ConnectionFactory connectionFactory,
|
||||
MessageListenerAdapter listenerAdapter) {
|
||||
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
container.setQueueNames(queueName);
|
||||
container.setMessageListener(listenerAdapter);
|
||||
return container;
|
||||
}
|
||||
|
||||
@Bean
|
||||
MessageListenerAdapter listenerAdapter(MessageConsumer messageReceiver) {
|
||||
return new MessageListenerAdapter(messageReceiver, "receiveMessage");
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.baeldung.springamqpsimple.broadcast;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class BroadcastConfig {
|
||||
|
||||
public final static String fanoutQueue1Name = "com.baeldung.spring-amqp-simple.fanout.queue1";
|
||||
public final static String fanoutQueue2Name = "com.baeldung.spring-amqp-simple.fanout.queue2";
|
||||
public final static String fanoutExchangeName = "com.baeldung.spring-amqp-simple.fanout.exchange";
|
||||
|
||||
public final static String topicQueue1Name = "com.baeldung.spring-amqp-simple.topic.queue1";
|
||||
public final static String topicQueue2Name = "com.baeldung.spring-amqp-simple.topic.queue2";
|
||||
public final static String topicExchangeName = "com.baeldung.spring-amql-simple.topic.exchange";
|
||||
|
||||
@Bean
|
||||
public Declarables topicBindings() {
|
||||
Queue topicQueue1 = new Queue(topicQueue1Name, false);
|
||||
Queue topicQueue2 = new Queue(topicQueue2Name, false);
|
||||
|
||||
TopicExchange topicExchange = new TopicExchange(topicExchangeName);
|
||||
|
||||
return new Declarables(
|
||||
topicQueue1,
|
||||
topicQueue2,
|
||||
topicExchange,
|
||||
BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"),
|
||||
BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Declarables fanoutBindings() {
|
||||
Queue fanoutQueue1 = new Queue(fanoutQueue1Name, false);
|
||||
Queue fanoutQueue2 = new Queue(fanoutQueue2Name, false);
|
||||
|
||||
FanoutExchange fanoutExchange = new FanoutExchange(fanoutExchangeName);
|
||||
|
||||
return new Declarables(
|
||||
fanoutQueue1,
|
||||
fanoutQueue2,
|
||||
fanoutExchange,
|
||||
BindingBuilder.bind(fanoutQueue1).to(fanoutExchange),
|
||||
BindingBuilder.bind(fanoutQueue2).to(fanoutExchange)
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SimpleRabbitListenerContainerFactory broadcastContainer(ConnectionFactory connectionFactory, SimpleRabbitListenerContainerFactoryConfigurer configurer) {
|
||||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
||||
configurer.configure(factory, connectionFactory);
|
||||
return factory;
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.baeldung.springamqpsimple.broadcast;
|
||||
|
||||
import com.baeldung.springamqpsimple.MessageConsumer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BroadcastMessageConsumers {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessageConsumer.class);
|
||||
|
||||
@RabbitListener(queues = {BroadcastConfig.fanoutQueue1Name})
|
||||
public void receiveMessageFromFanout1(String message) {
|
||||
logger.info("Received fanout 1 message: " + message);
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {BroadcastConfig.fanoutQueue2Name})
|
||||
public void receiveMessageFromFanout2(String message) {
|
||||
logger.info("Received fanout 2 message: " + message);
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {BroadcastConfig.topicQueue1Name})
|
||||
public void receiveMessageFromTopic1(String message) {
|
||||
logger.info("Received topic 1 message: " + message);
|
||||
}
|
||||
|
||||
@RabbitListener(queues = {BroadcastConfig.topicQueue2Name})
|
||||
public void receiveMessageFromTopic2(String message) {
|
||||
logger.info("Received topic 2 message: " + message);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.baeldung.springamqpsimple.broadcast;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@Controller
|
||||
public class BroadcastMessageController {
|
||||
|
||||
private final BroadcastMessageProducer messageProducer;
|
||||
|
||||
@Autowired
|
||||
public BroadcastMessageController(BroadcastMessageProducer messageProducer) {
|
||||
this.messageProducer = messageProducer;
|
||||
}
|
||||
|
||||
@RequestMapping(value="/broadcast", method= RequestMethod.POST)
|
||||
@ResponseStatus(value= HttpStatus.CREATED)
|
||||
public void sendMessage(@RequestBody String message) {
|
||||
messageProducer.sendMessages(message);
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.baeldung.springamqpsimple.broadcast;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class BroadcastMessageProducer {
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
public BroadcastMessageProducer(RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
}
|
||||
|
||||
public void sendMessages(String message) {
|
||||
rabbitTemplate.convertAndSend(BroadcastConfig.fanoutExchangeName, "", message);
|
||||
rabbitTemplate.convertAndSend(BroadcastConfig.topicExchangeName, "user.not-important.info", message);
|
||||
rabbitTemplate.convertAndSend(BroadcastConfig.topicExchangeName, "user.important.error", message);
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
spring:
|
||||
rabbitmq:
|
||||
username: guest
|
||||
password: guest
|
||||
host: 10.10.10.105
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
@ -1,16 +0,0 @@
|
||||
package org.baeldung;
|
||||
|
||||
import com.baeldung.springamqpsimple.SpringAmqpApplication;
|
||||
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(classes = SpringAmqpApplication.class)
|
||||
public class SpringContextManualTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
spring:
|
||||
rabbitmq:
|
||||
username: guest
|
||||
password: guest
|
||||
host: localhost
|
Loading…
x
Reference in New Issue
Block a user