赞
踩
简单案例
其案例之前要确定你安装了RabbitMQ 并且启动了RiabbitMQ
启动lunix 并打开
一般我们会设置 Rabbit是自动启动的,但害怕失效.所以再重启下:
systemctl start rabbitmq-server
新建springboot 或maven工程
pox.xml样要
- <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.3.2.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>cn.tedu</groupId>
- <artifactId>rabbitmq-springboot</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>rabbitmq-springboot</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-amqp</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
新建消费方consumer 提供,:producer测试方Main1
- package cn.tedu.rabbitmqspringboot.m1;
-
- import org.springframework.amqp.rabbit.annotation.Queue;
- import org.springframework.amqp.rabbit.annotation.RabbitHandler;
- import or
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。