原创转载请注明出处: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的更多相关文章

  1. 使用webstorm+webpack构建简单入门级“HelloWorld”的应用&&引用jquery来实现alert

    使用webstorm+webpack构建简单入门级"HelloWorld"的应用&&构建使用jquery来实现 1.首先你自己把webstorm安装完成. 请参考这 ...

  2. Idea下用SBT搭建Spark Helloworld

    没用过IDEA工具,听说跟Eclipse差不多,sbt在Idea其实就等于maven在Eclipse.Spark运行在JVM中,所以要在Idea下运行spark,就先要安装JDK 1.8+ 然后加入S ...

  3. 菜鸟学Struts2——HelloWorld

    写在前面 自从工作后就过上了只有一个月记忆的生活,太健忘,很多学过的东西因为用得少便忘记了,第二次学习struts,为了以后便于查阅,开始自己的博客之旅.Struts的学习还是从Hello World ...

  4. 初识AngularJS 之 HelloWorld和数据绑定

    1.Hello World 我用的开发工具是   atom   ,大家有需要的话可以找我要安装包嘻嘻 第一步: 写入以下代码: <!DOCTYPE html> <html ng-ap ...

  5. java环境搭建和写出一个Helloworld

    一.安装环境和配置环境变量(必要环节) 安装java并配置环境变量 :在"系统变量"中设置3项属性,JAVA_HOME,PATH,CLASSPATH(大小写无所谓),若已存在则点击 ...

  6. Delphi_01_控制台版HelloWorld

    对于Windows下的控制台编程,我相信很多人都不陌生.而C语言开始的著名的“Hello world”程序基本是学习编程的第一步.我想对于 RAD开发,大家熟悉的一般都是GUI编程,而对于consol ...

  7. Quartz —— 从 HelloWorld 开始

    1.Quartz 是用来完成任务调度的. 2.Quartz 的三个核心概念:调度器.任务.触发器. (1)Job:通过实现该接口来定义需要执行的任务. public interface Job { / ...

  8. 转载文章——从HelloWorld学习操作系统

    转载地址:https://my.oschina.net/hosee/blog/673628?p=%7b%7bcurrentPage+1%7d%7d 本文就将系统性的串联起那些知识点,方便复习和回顾.本 ...

  9. AngularJS 系列 01 - HelloWorld和数据绑定

    目录导读: AngularJS 系列 学习笔记 目录篇 前言: 好记性不如烂键盘,随笔就是随手笔记,希望以后有用. 本篇目录: 1. Hello World 2. AngularJS中的数据绑定 3. ...

随机推荐

  1. day03-Python基础

    1:函数 定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 减少重复代码 使程序变的可扩展 使程序变得易维护 函数定义: def sayh ...

  2. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第5节 String类_7_字符串的转换相关方法

    sequence n.顺序:次序:一系列:一连串 v.按顺序排列:测定(整套基因或分子成分的)序列 网络连续:数列:时序 butes.fori出循环 replace Ctrl+字母N也可以打开 输入s ...

  3. 04 bbed修复system文件头损坏

    04 bbed修复system文件头损坏 1 启动数据库,查看trace,在mount到open, SQL> startup mount; ORACLE instance started. To ...

  4. 不起眼的vim.转自https://blog.csdn.net/iplayvs2008/article/details/51508599

    如果我的关于这个话题的最新帖子没有提醒到你的话,那我明确地说,我是一个 Vim 的粉丝.所以在你们中的某些人向我扔石头之前,我先向你们展示一系列“鲜为人知的 Vim 命令”.我的意思是,一些你可能以前 ...

  5. 5G调研与总结

    5G的重点是: 将极大地超越现有的4G,主要包括速度,时延,带宽,能耗等方面 传输速度的快速提高(相对于4G来说提升了近10倍),在万物物联上的作用会更大 由于传速度快,让各种远程操控成为了可能(AR ...

  6. Vue路由注意事项

    一.vue中路由的使用 1.定义组件 <template> <div class="hello"> <h1 @click="info&quo ...

  7. python基础-7模块,第三方模块安装方法,使用方法。sys.path os sys time datetime hashlib pickle json requests xml

    模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...

  8. [Web 前端] 003 html 表单标签

    目录 表单标签 1. form 标签 2. 表单控件 2.1 登录框 2.2 单选按钮 2.3 多选按钮 3. select 标签 4 文件上传 5. textarea 标签 6. 按钮 7. 隐藏域 ...

  9. getCurrentSession 与 openSession区别

    getCurrentSession () 使用当前的session openSession()重新建立一个新的session 使用SessionFactory.getCurrentSession()需 ...

  10. Codeforces - 6E - Exposition - 尺取

    https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...