springboot与RabbitMQ的快速搭建
2016-09-02 00:00
555 查看
直接进入正题,有关mq的知识参考上一篇,其实这个和activemq在性能上差不多,只不过他是依赖amqp协议,同时rabbitmq是用erlang语言写的
还有一个是直接docker pull rabbitmq,但是会映射出来4个接口5671 25672 4369 5672,且没有管理界面,不推荐使用,我被坑过!!
**rabbitmq界面 **
**默认密码:guest/guest,**进入的页面为:
可以看到队列,通道,交换机之类的东西
application.properties
springboot对其有默认配置,这个可以在联想的代码中直接看到,比如username和paaword之类的,我这里如果是默认的localhost的话也不需要配置,由于我这里不是默认的,必须要自定义配置
2.新建queue和监听
3,测试代码
4,启动并测试
http://localhost:8080/rabbit-test
得到的结果为
rabbit界面为:
已经新建了一个名为my-queue队列,同时也监听到了消息。
1,安装RabbitMq
#这个带有管理界面 docker pull rabbitmq:3-management
还有一个是直接docker pull rabbitmq,但是会映射出来4个接口5671 25672 4369 5672,且没有管理界面,不推荐使用,我被坑过!!
#启动容器 docker run -itd -p 5672:5672 -p 15672:15672 cb479f313c93
**rabbitmq界面 **
**默认密码:guest/guest,**进入的页面为:
可以看到队列,通道,交换机之类的东西
2.代码部分
添加依赖配置application.properties<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency>
application.properties
springboot对其有默认配置,这个可以在联想的代码中直接看到,比如username和paaword之类的,我这里如果是默认的localhost的话也不需要配置,由于我这里不是默认的,必须要自定义配置
2.新建queue和监听
package com.lijunhao.rabbitmq; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Configurable; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; /** * 新建队列 * @author lijunhao * */ @Component public class MyQueue { /**只是声明一个叫my-queue的队列 import org.springframework.amqp.core.Queue,包不要引错了 */ @Bean public Queue rabbitQueue(){ return new Queue("my-queue"); } /** * 声明一个监听者,监听my-queue队列的消息,可以多选,队列名用逗号隔开 * @param message */ @RabbitListener(queues = "my-queue") public void receiveMessage(String message){ System.out.println("接收到来自RabbitMq的消息:"+message); } }
3,测试代码
/** * 测试发送RabbitMq消息 * lijunhao * @return */ @RequestMapping(value="/rabbit-test") public String getTestRabbitMQ(){ rabbitTemplate.convertAndSend("my-queue", "hello-rabbitMQ.from 2016-09-02"); return "index"; }
4,启动并测试
http://localhost:8080/rabbit-test
得到的结果为
rabbit界面为:
已经新建了一个名为my-queue队列,同时也监听到了消息。
相关文章推荐
- 快速搭建springboot框架以及整合ssm+shiro+安装Rabbitmq和Erlang、Mysql下载与配置
- spring boot 快速搭建 基于 Restful 风格的微服务
- 聊聊SpringBoot | 第一章:快速搭建SpringBoot第一个应用
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- springboot快速搭建
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- SpringBoot-快速搭建WEB工程
- 用Spring Boot & Cloud,Angular2快速搭建微服务web应用 - AngularJS2客户端
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 使用SpringBoot快速搭建服务器
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- 【SpringBoot教程二】:RESTfull API简单项目的快速搭建
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程
- Spring Boot+JPA+Mysql+ThymeLeaf快速构建CURD系统(二)搭建SpringBoot工程