rabbitMQ 与springboot整合报错AMQP协议版本不匹配,如何解决?

问题描述

控制台显示AMQP protocol version mismatch; we are version 0-9-1, server sent signature 3,1,0,0

问题出现的环境背景及自己尝试过哪些方法

看到一个博主说要ssl证书 或者是和activeMQ冲突了 但是还是不太好用
正常一个springboot与rabbitmq的整合

相关代码

POM文件:
<?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.5.6</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<groupId>com.example</groupId>

<artifactId>RabbitMQDemo</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>RabbitMQDemo</name>

<description>RabbitMQDemo</description>

<properties>

<java.version>1.8</java.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter</artifactId>

</dependency>

<!-- web -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<!-- swagger -->

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger2</artifactId>

<version>2.9.2</version>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger-ui</artifactId>

<version>2.9.2</version>

</dependency>

<!-- rabbitmq -->

<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>

配置文件:

spring.rabbitmq.host=127.0.01
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

package com.example.rabbitmqdemo.config;

import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

rabbitMQ配置文件:

@Configuration
public class RabbitConfig {

@Bean

public Queue demoString(){

return new Queue("demoQueue");

}

}

SWagger配置文件:

package com.example.rabbitmqdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean

public Docket createRestApi() {

return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())

.select()

.apis(RequestHandlerSelectors.any())

.paths(PathSelectors.any()).build();

}

private ApiInfo apiInfo() {

return new ApiInfoBuilder()

.title("Swagger ApI Doc")

.description("This is a restful api document cf Swagger.")

.version("1.0")

.build();

}

}

消费者
package com.example.rabbitmqdemo.send;

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

@Component
@RabbitListener(queues = "demoQueue")
public class Consumer {

@RabbitHandler

public void recieved(String msg) {

System.out.println("[demoQueue] recieved message" + msg);

}

}

生产者

package com.example.rabbitmqdemo.send;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class RabbitProducer {

@Autowired

private AmqpTemplate rabbitTemplate;

public void sendDemoQueue() {

Date date = new Date();

String dateString = new SimpleDateFormat("YYYY-mm-dd hh:MM:ss").format(date);

System.out.println("[demoQueue] send msg:" + dateString);

this.rabbitTemplate.convertAndSend("demoQueue", dateString);

}

}

controller:

@RestController
public class RabbitMqController {

@Autowired

private RabbitProducer rabbitProducer;

@GetMapping("/sendDemoQueue")

public Object sendDemoQueue(){

rabbitProducer.sendDemoQueue();

return "success";

}

}

你期待的结果是什么?实际看到的错误信息又是什么?

以上是 rabbitMQ 与springboot整合报错AMQP协议版本不匹配,如何解决? 的全部内容, 来源链接: utcz.com/p/944092.html

回到顶部