RMQ HelloWorld
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11791681.html
Project Directory

Maven Dependency
<?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>org.fool.rmq</groupId>
<artifactId>rmq</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</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> <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>
application.properties
spring.application.name=rmq
server.port= spring.rabbitmq.host=localhost
spring.rabbitmq.port=
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin
Source Code
Application.java
package org.fool.rmq; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
RmqConfig.java
package org.fool.rmq.config; import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class RmqConfig { @Bean
public Queue queue() {
return new Queue("hello-rmq");
}
}
Producer.java
package org.fool.rmq.producer; import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import java.util.Date; @Component
public class Producer {
@Autowired
private AmqpTemplate rmqTemplate; public void send() {
String message = "Hello " + new Date();
rmqTemplate.convertAndSend("hello-rmq", message);
}
}
Consumer.java
package org.fool.rmq.consumer; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component; @Component
public class Consumer {
@RabbitListener(queues = "hello-rmq")
public void handle(String message) {
System.out.println("consume: " + message);
}
}
ApplicationTest.java
package org.fool.rmq.test; import org.fool.rmq.Application;
import org.fool.rmq.producer.Producer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ApplicationTest { @Autowired
private Producer producer; @Test
public void test() {
producer.send();
}
}
Console Output

RMQ Management

RMQ HelloWorld的更多相关文章
- 使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&引用jquery来实现alert
使用webstorm+webpack构建简单入门级"HelloWorld"的应用&&构建使用jquery来实现 1.首先你自己把webstorm安装完成. 请参考这 ...
- Idea下用SBT搭建Spark Helloworld
没用过IDEA工具,听说跟Eclipse差不多,sbt在Idea其实就等于maven在Eclipse.Spark运行在JVM中,所以要在Idea下运行spark,就先要安装JDK 1.8+ 然后加入S ...
- 菜鸟学Struts2——HelloWorld
写在前面 自从工作后就过上了只有一个月记忆的生活,太健忘,很多学过的东西因为用得少便忘记了,第二次学习struts,为了以后便于查阅,开始自己的博客之旅.Struts的学习还是从Hello World ...
- 初识AngularJS 之 HelloWorld和数据绑定
1.Hello World 我用的开发工具是 atom ,大家有需要的话可以找我要安装包嘻嘻 第一步: 写入以下代码: <!DOCTYPE html> <html ng-ap ...
- java环境搭建和写出一个Helloworld
一.安装环境和配置环境变量(必要环节) 安装java并配置环境变量 :在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击 ...
- Delphi_01_控制台版HelloWorld
对于Windows下的控制台编程,我相信很多人都不陌生.而C语言开始的著名的“Hello world”程序基本是学习编程的第一步.我想对于 RAD开发,大家熟悉的一般都是GUI编程,而对于consol ...
- Quartz —— 从 HelloWorld 开始
1.Quartz 是用来完成任务调度的. 2.Quartz 的三个核心概念:调度器.任务.触发器. (1)Job:通过实现该接口来定义需要执行的任务. public interface Job { / ...
- 转载文章——从HelloWorld学习操作系统
转载地址:https://my.oschina.net/hosee/blog/673628?p=%7b%7bcurrentPage+1%7d%7d 本文就将系统性的串联起那些知识点,方便复习和回顾.本 ...
- AngularJS 系列 01 - HelloWorld和数据绑定
目录导读: AngularJS 系列 学习笔记 目录篇 前言: 好记性不如烂键盘,随笔就是随手笔记,希望以后有用. 本篇目录: 1. Hello World 2. AngularJS中的数据绑定 3. ...
随机推荐
- seq使用
转载! 用于产生从某个数到另外一个数之间的所有整数例一:# seq 1 10结果是1 2 3 4 5 6 7 8 9 10例二:#!/bin/bashfor i in `seq 1 10`;doech ...
- 阶段1 语言基础+高级_1-3-Java语言高级_04-集合_02 泛型_2_使用泛型的好处
用一个案例说明使用泛型和不是用泛型的区别 这里的ArrayList没写数据类型,不写就是默认Object 多态的弊端,不能使用子类特有的方法 向下转型,转换为String类型,才能使用length 不 ...
- #Week 11 - 343.Integer Break
Week 11 - 343.Integer Break Given a positive integer n, break it into the sum of at least two positi ...
- 券商VIP交易通道
打新不成就炒新.随着新股发行上市的再次重启,巨大的获利机会引来投资者的争相竞逐,可并非所有投资者都能抢到新股筹码.“每天都在涨停板追这些新股,但从来没有买到过.”证券时报记者在采访中听到不少中小散户如 ...
- 伪造IP及获取客户端真实IP地址
Fiddler支持自定义规则,可以实现对HTTP请求数据发送给Server前或HTTP应答数据发送给浏览器前进行修改.下面的例子将演示如何向所有HTTP请求数据中增加一个头.1)打开Fiddler,点 ...
- Matlab入门基础
matlab入门篇,一些基础用法记一下~ M语言是解释型语言 who:查看当前变量 whoes:查看当前变量及其维数.所占字节数等. clear: 清除所有变量 clear + 变量名 ...
- WPF资源字典的使用
1.在解决方案中添加资源字典:鼠标右键——添加——资源字典 2.在资源字典中写入你需要的样式,我这里简单的写了一个窗体的边框样式 3.在App.xaml中加入刚刚新建的资源字典就好了
- oracle--单行函数和多行函数
单行函数 1.字符函数 函 数 功 能 示 例 结 果 INITCAP (char) 首字母大写 initcap ('hello') Hello LOWER (char) 转换为小写 lower ...
- oracle--少见操作、如何调整dos窗口大小、字符集设置
如何调整dos窗口大小 1.set linesize 400; 2.右键 --默认值 断开.连接 disconn ; conn ww/ww; 关于字符集 操作系统环境变量针对语言项设置有几个,我经常设 ...
- JAVA总结--jvm
VM,Virtual Machine 即虚拟机,指通过软件模拟的具有完整硬件系统功能的.运行在一个完全隔离环境中的完整计算机系统. JVM,Java Virtual Machine 即Java虚拟机, ...