RabbitMQ入门

RabbitMQ入门,第1张

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

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5701828.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存