栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

RabbitMQ入门

RabbitMQ入门

安装

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连接RabbitMQ

pom.xml



	4.0.0
	
		org.springframework.boot
		spring-boot-starter-parent
		1.5.10.RELEASE
		 
	
	org.cc.springboot
	rabbitmq
	0.0.1-SNAPSHOT
	rabbitmq
	Demo project for Spring Boot
	
		1.8
	
	
		
			org.springframework.boot
			spring-boot-starter-amqp
		

		
		    org.springframework.boot
		    spring-boot-starter-web
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
		
		
			junit
			junit
			test
		
		
	

	
		
			
				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();
	}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701719.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号