Linux版本安装
在CentOS 7上安装RabbitMQ服务器 | 《Linux就该这么学》
RabbitMQ RPM包下载地址:https://github.com/rabbitmq/rabbitmq-server/releases
如果需要远程访问可以关闭防火墙
systemctl stop firewalld.service
Windows版本
Erlang24.0+RabbitMQ3.8.16安装及配置_icqcqi的博客-CSDN博客_erlang24 安装
一,rabbitmq web端管理cd sbin
rabbitmq-plugins.bat enable rabbitmq_management
rabbitmqctl.bat add_user rabbitmq rabbitmq
rabbitmqctl.bat set_user_tags rabbitmq administrator
rabbitmqctl.bat set_permissions -p "/" rabbitmq ".*" ".*" ".*"
浏览器访问http://localhost:15672/ 用户名/密码:rabbitmq/rabbitmq
二,springboot连接RabbitMQpom.xml
4.0.0 org.springframework.boot spring-boot-starter-parent1.5.10.RELEASE org.cc.springboot rabbitmq0.0.1-SNAPSHOT rabbitmq Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-amqporg.springframework.boot spring-boot-starter-weborg.springframework.boot spring-boot-starter-testtest junit junittest org.springframework.boot spring-boot-maven-plugin
properties
spring.application.name=rabbitmq server.port:8080 spring.rabbitmq.host=127.0.0.1 spring.rabbitmq.port=5672 spring.rabbitmq.username=rabbitmq spring.rabbitmq.password=rabbitmq
SendConfig
@Configuration public class SendConfig { @Bean public Queue queue(){ return new Queue("my queue"); } }
Sender
@Component public class Sender { @Autowired private AmqpTemplate rabbitTemplate; public void send(){ String msg = "hello"+new Date(); rabbitTemplate.convertAndSend("my queue",msg); } }
Receiver
@Component public class Receiver { @RabbitListener(queues="my queue") public void receive(String msg){ System.out.println("receive:"+msg); } }
RabbitmqApplicationTests
@RunWith(SpringRunner.class) @SpringBootTest(classes=RabbitmqApplication.class) public class RabbitmqApplicationTests { @Autowired private Sender sender; @Test public void send() { this.sender.send(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)