关键词不能为空

当前您在: 主页 > 英语 >

RabbitMQ集群使用说明

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-15 14:42
tags:

-

2021年2月15日发(作者:zam)



文件编号:























号:







V1.0










RabbitMQ


集群使用说明












写:




































核:




































准:

































文档修改记录




版本号



修订日期










变更概述





作者
























1.



Maven


配置


pom




中加入


rabbitmq



spring rabbitmq


依赖包。






















<


dep endency


>




<


groupId


>


mq



groupId


>



<


artifactId


>


amqp-client


< p>
artifactId


>




<


version

< br>>


3.5.4



versio n


>




d ependency


>



<

< p>
dependency


>




<


groupId

< br>>




groupId


>




<


artifactId


>


spring-rabbi t



artifactId


>




<


versio n


>


E



v ersion


>




dependency


>



2.



使用


Java API


直接连接


RabbitMQ


集群



使用官方的


Java API




)来直接连接


RabbitMQ


集群。



2.1



RabbitMQ


发送



直接连接


RabbitMQ


集群,然后发送消息。< /p>



import


s;


import


l;


import


tion;


import


tionFactory;



public



class


RabbitMqSend2 {



private



final



static


String


QUEUE_NAME


=



;





public



static



void


main(String[]


args


)


throws


Exception {




Address[]


addrArr


=


new


Address[] {






new


Address(



, 5672),






new


Address(



, 5672) ,






new


Address(



, 5672) };





ConnectionFactory


factory


=


new


ConnectionFactory();




factory

< br>.setUsername(



);




factory

< br>.setPassword(



);




factory

< br>.setVirtualHost(



);















}












}



Connection


connection


=


fact ory


.newConnection(


addrArr


);


Channel


channel


=


connection


.createChannel();


for


(


int



i


= 1;


i


<= 10;


i


++) {



String


message


=



+


i


;



channel


.basicPub lish(



,


QUEUE_NAME


,


null


,


message


.getBytes());



System.


out


.println(


i


+



+


message


+



);



Thread.


sleep


(1);


}


System.


exit


(0);


2.2



RabbitMQ


接收



直接连接


RabbitMQ


集群,然后接收消息,注 意需要手动打开应答机制,并


手动提交确认消息,保证公平调度和消息持久化。




import


s;


import


l;


import


tion;


import


tionFactory;


import


ngConsumer;



public



class


RabbitMqRecv2 {



private



final



static


String


QUEUE_NAME


=



;




public



static



void


main(String[]


argv


)


throws


Exception {




Address[]


addrArr


=


new


Address[] {






new


Address(



, 5672),






new


Address(



, 5672) ,






new


Address(



, 5672) };





ConnectionFactory


factory


=


new


ConnectionFactory();




factory

< br>.setUsername(



);




factory

< br>.setPassword(



);




factory

< br>.setVirtualHost(



);




Connection


connection


=


fact ory


.newConnection(


addrArr


);




Channel


channel


=


connection


.createChannel();

-


-


-


-


-


-


-


-



本文更新与2021-02-15 14:42,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/655494.html

RabbitMQ集群使用说明的相关文章