Last active
March 3, 2018 22:44
-
-
Save garyrussell/e003474483eb604ee2362d28125d0165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2018-03-03 17:39:54.599 INFO 2182 --- [ main] com.example.RabbitmqUsers1Application : FOO | |
2018-03-03 17:39:54.603 INFO 2182 --- [ main] com.example.RabbitmqUsers1Application : BAR | |
2018-03-03 17:39:54.607 INFO 2182 --- [ main] com.example.RabbitmqUsers1Application : BAZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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.example</groupId> | |
<artifactId>rabbitmq-users-1</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>jar</packaging> | |
<name>rabbitmq-users-1</name> | |
<description>Demo project for Spring Boot</description> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>2.0.0.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-test</artifactId> | |
<scope>test</scope> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
public class RabbitmqUsers1Application { | |
private final Logger logger = LoggerFactory.getLogger(RabbitmqUsers1Application.class); | |
public static void main(String[] args) { | |
SpringApplication.run(RabbitmqUsers1Application.class, args); | |
} | |
@Bean | |
public ApplicationRunner runner(RabbitTemplate template) { | |
return args -> { | |
ParameterizedTypeReference<String> returnTypeString = new ParameterizedTypeReference<String>() { }; | |
logger.info(template.convertSendAndReceiveAsType("myExchange", "rk", "foo", returnTypeString)); | |
logger.info(template.convertSendAndReceiveAsType("myExchange", "rk", "bar", returnTypeString)); | |
logger.info(template.convertSendAndReceiveAsType("myExchange", "rk", "baz", returnTypeString)); | |
}; | |
} | |
@RabbitListener(queues = "myQueue") | |
public String upCase(String in) { | |
return in.toUpperCase(); | |
} | |
@Bean | |
public MessageConverter jsonConverter() { | |
return new Jackson2JsonMessageConverter(); | |
} | |
@Bean | |
public DirectExchange exchange() { | |
return new DirectExchange("myExchange"); | |
} | |
@Bean | |
public Queue queue() { | |
return new Queue("myQueue"); | |
} | |
@Bean | |
public Binding binding() { | |
return BindingBuilder.bind(queue()).to(exchange()).with("rk"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment