真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

rabbitmq的direct和fanout模式-創(chuàng)新互聯(lián)

rabbitmq的direct和fanout模式

流程:rabbitmq的direct和
fanout模式
  1. 請(qǐng)求鏈接并發(fā)送mq
  2. 消費(fèi)者獲取mq并處理

請(qǐng)求鏈接并發(fā)送mq
controller(IndexController):

創(chuàng)新互聯(lián)主要從事網(wǎng)站設(shè)計(jì)、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)米脂,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
@Autowired
private IndexService indexService;

@ResponseBody
@RequestMapping(value="/direct")
public void direct(){
	log.info("[rabbitmq][direct][start]");
	indexService.sendDirect();
	log.info("[rabbitmq][direct][end]");
}

@ResponseBody
@RequestMapping(value="/fanout")
public void fanout(){
	log.info("[rabbitmq][fanout][start]");
	indexService.sendFanout();
	log.info("[rabbitmq][fanout][end]");
}

service(IndexService):

@Resource(name = "direct-template")
private RabbitTemplate templateDirect;
@Resource(name = "fanout-template")
private RabbitTemplate fanoutDirect;

public void sendDirect(){
	Message message = new Message<>();
	message.setAction("DIRECT_TEST");
	message.setData("DIRECT");
	log.info("Message:"+message.getData());
	templateDirect.convertAndSend(message);
}

public void sendFanout(){
	Message message = new Message<>();
	message.setAction("FANOUT_TEST");
	message.setData("FANOUT");
	log.info("Message:"+message.getData());
	fanoutDirect.convertAndSend(message);
}

消費(fèi)者獲取mq并處理:
1.direct 方式



	
		
	

	

		
	

	

DirectListener:

@Override
public void accept(String messageContent) throws Throwable {
	log.info("direct listener");
}

2.fanout方式




	
		
		
	

	
	

		
	

	
		

FanoutListener1:

@Override
public void accept(String messageContent) throws Throwable {
	log.info("fanout listener11111111111111");
}

FanoutListener2:

@Override
public void accept(String messageContent) throws Throwable {
	log.info("fanout listener222222222222222");
}

運(yùn)行代碼,訪問(wèn)鏈接,查看結(jié)果。
訪問(wèn)/direct

[com.controller.IndexController]-[INFO] [rabbitmq][direct][start]
[com.service.IndexService]-[INFO] Message:DIRECT
[com.controller.IndexController]-[INFO] [rabbitmq][direct][end]
[com.listener.DirectListener]-[INFO] direct listener

訪問(wèn)/fanout

[com.controller.IndexController]-[INFO] [rabbitmq][fanout][start]
[com.service.IndexService]-[INFO] Message:FANOUT
[com.controller.IndexController]-[INFO] [rabbitmq][fanout][end]
[com.listener.FanoutListener2]-[INFO] fanout listener222222222222222
[com.listener.FanoutListener1]-[INFO] fanout listener11111111111111

名稱欄目:rabbitmq的direct和fanout模式-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://weahome.cn/article/dhhioc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部