首先你要自己安装一个RabbitMQ,这里是安装包
由于RabbitMQ是用Erlang语言编写的,因此需要先安装Erlang。
https://www.rabbitmq.com/install-windows.html
https://www.erlang.org/downloads
下面进入正题
首先是pom文件
<!-- amqp -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
rabbit的配置类,这个类里面可以配置messageconverter等。这里可以根据自己的需要补充
package com.wc.www.ScBus.mq;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**默认支持SimpleMessageConverter,
* java.lang.IllegalArgumentException: SimpleMessageConverter only supports String, byte[]
* and Serializable payloads, received: com.wc.www.ScBus.entity.Teacher
* @author Administrator
*
*/
@Configuration
public class RabbitConfig {
@Bean
public Queue helloQueue() {
return new Queue("helloMQ"); //配置一个名称为"hello"的Queue队列
}
/*
* @Bean public RabbitListenerContainerFactory<?>
* rabbitListenerContainerFactory(ConnectionFactory connectionFactory){
* SimpleRabbitListenerContainerFactory factory = new
* SimpleRabbitListenerContainerFactory();
* factory.setConnectionFactory(connectionFactory);
* factory.setMessageConverter(new Jackson2JsonMessageConverte