RabbitMQ消费者demo

Posted lizhen1412

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RabbitMQ消费者demo相关的知识,希望对你有一定的参考价值。

RabbitMQ消费者Demo

备注:

只需要修改queues

技术图片
<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>RabbitMQ-Consumption</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>RabbitMQ-Consumption</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-amqp</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>
pom.xml
技术图片
spring.rabbitmq.addresses=base-testmq.ttbike.com.cn
spring.rabbitmq.username=bonus_mq
spring.rabbitmq.password=bonus_mq
spring.rabbitmq.virtual-host=bonus_mq
spring.rabbitmq.listener.simple.prefetch=1000
application.properties
技术图片
package com.example.demo.Consumer;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class Consumer 
    @RabbitListener(queues = "ride_info_queue")
    @RabbitHandler
    public void process(String hello) 
    

Consumer

 

以上是关于RabbitMQ消费者demo的主要内容,如果未能解决你的问题,请参考以下文章

RabbitMQ应用Demo:支持多个消费者实例热插拔

RabbitMQ应用Demo:支持多个消费者实例热插拔

RabbitMQ应用Demo:支持多个消费者实例热插拔

springboot rabbitMQ demo

RabbitMQ入门小Demo

rabbitmq入门