RabbitMq的安装环境为CentOS7.0
其中安装部分可以参考http://blog.csdn.net/zheng911209/article/details/49945677
访问在系统中访问:127.0.0.1:15672 使用guest/guest,可以进入的RabbitMq的web管理界面
不过如果要结合Sping Boot进行开发,还需要做额外的步骤,因为https://www.rabbitmq.com/access-control.html官方文档说了guest只可以进行本地的访问,如果需要使用远程ip进行访问,则要给rabbitmq新建一个新的用户
最好在root权限下新建用户
[root@localhost ~]# rabbitmqctl add_user root root
Creating user "root" ...
[root@localhost ~]# rabbitmqctl set_user_tags root administrator
Setting tags for user "root" to [administrator] ...
[root@localhost ~]# rabbitmqctl set_permissions -p / root ".*" ".*" ".*"
Setting permissions for user "root" in vhost "/" ...
如果能再远程ip下使用自己建立的用户进行登陆,那就可以进行代码编写
其中rabbitmq的两个端口:
5672:rabbitmq服务器监听的端口,客户端连接服务器的端口
15672/55672:rabbitmq管理网站管理页面的端口
简单集成springboot很简单,只需要注意下面说的几个点
application.yml
在配置中,rabbitmq用的端口是5672,因为5672才是服务器的监听端口,15672是rabbitmq管理网站管理页面的端口
spring:
application:
name: rabbitmqTest
rabbitmq:
host: 192.168.1.106
port: 5672
username: root
password: root
接收者和发送者只要注意队列名字(queue name)一致就可以接收数据
RabbitmqTest
@SpringBootTest是至spring-boot-test 1.40开始启用,spring-boot-test 1.40之前使用@SpringApplicationConfiguration
@RunWith(SpringRunner.class)
@SpringBootTest
public class RabbitmqTest {
@Autowired
private Sender sender;
@Test
public void helloTest()
{
sender.send();
}
}
Demo: https://github.com/tale2009/springbbot_rabbitmq