国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - springboot實(shí)現(xiàn)rabbitmq的隊(duì)列初始化和綁定

springboot實(shí)現(xiàn)rabbitmq的隊(duì)列初始化和綁定

2021-06-02 14:20張占嶺(倉儲(chǔ)大叔,Lind) Java教程

這篇文章主要介紹了springboot實(shí)現(xiàn)rabbitmq的隊(duì)列初始化和綁定,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

配置文件,在rabbit中自動(dòng)建立exchange,queue和綁定它們的關(guān)系

  1. 代碼里初始化exchange
  2. 代碼里初始化queue
  3. 代碼里綁定exchange,queue和routekey
  4. 配置文件,直接聲明vhost

代碼里初始化exchange

?
1
2
3
4
5
6
7
8
9
/**
  * rabbitmq里初始化exchange.
  *
  * @return
  */
 @bean
 public topicexchange crmexchange() {
  return new topicexchange(exchange);
 }

代碼里初始化queue

?
1
2
3
4
5
6
7
8
9
/**
  * rabbitmq里初始化隊(duì)列crm.hello.
  *
  * @return
  */
 @bean
 public queue helloqueue() {
  return new queue(hello);
 }

代碼里綁定exchange,queue和routekey

?
1
2
3
4
5
6
7
8
9
10
11
/**
  * 綁定exchange & queue & routekey.
  *
  * @param queuemessage 隊(duì)列
  * @param exchange   交換機(jī)
  * @param routekey   路由
  * @return
  */
 public binding bindingexchange(queue queuemessage, topicexchange exchange, string routekey) {
  return bindingbuilder.bind(queuemessage).to(exchange).with(routekey);
 }

配置文件

?
1
2
3
4
5
6
7
spring:
  rabbitmq:
  host: localhost
  port: 5672
  username: guest
  password: guest
  virtual-host: lind

完整代碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.lind.microservice.productcenter.mq;
 
import org.springframework.amqp.core.binding;
import org.springframework.amqp.core.bindingbuilder;
import org.springframework.amqp.core.queue;
import org.springframework.amqp.core.topicexchange;
import org.springframework.context.annotation.bean;
import org.springframework.context.annotation.configuration;
 
/**
 * amqp配置.
 */
@configuration
public class amqpconfig {
 
 /**
  * 交換機(jī).
  */
 public final static string exchange = "crm";
 /**
  * hello隊(duì)列.
  */
 public final static string hello = "crm.hello";
 /**
  * 建立訂單隊(duì)列.
  */
 public final static string lind_generate_order = "crm.generate.order";
 
 
 /**
  * 綁定exchange & queue & routekey.
  *
  * @param queuemessage 隊(duì)列
  * @param exchange   交換機(jī)
  * @param routekey   路由
  * @return
  */
 public binding bindingexchange(queue queuemessage, topicexchange exchange, string routekey) {
  return bindingbuilder.bind(queuemessage).to(exchange).with(routekey);
 }
 
 
 /**
  * rabbitmq里初始化exchange.
  *
  * @return
  */
 @bean
 public topicexchange crmexchange() {
  return new topicexchange(exchange);
 }
 
 /**
  * rabbitmq里初始化隊(duì)列crm.hello.
  *
  * @return
  */
 @bean
 public queue helloqueue() {
  return new queue(hello);
 }
 
 /**
  * rabbitmq里初始化隊(duì)列crm.generate.order.
  *
  * @return
  */
 @bean
 public queue orderqueue() {
  return new queue(lind_generate_order);
 }
}

隊(duì)列發(fā)布者

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.lind.microservice.productcenter.mq;
 
import java.util.date;
import org.springframework.amqp.core.amqptemplate;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.context.annotation.configuration;
 
@configuration
public class hellopublisher {
 @autowired
 amqptemplate rabbittemplate;
 @autowired
 amqpconfig amqpconfig;
 
 public void hello() {
  string context = "hello " + new date();
  system.out.println("hellopublisher : " + context);
  amqpconfig.bindingexchange(
    amqpconfig.helloqueue(),
    amqpconfig.crmexchange(),
    "crm.hello.#"
  );
  this.rabbittemplate.convertandsend(amqpconfig.exchange, amqpconfig.hello, context);
 }
}

隊(duì)列訂閱者

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package com.lind.microservice.productcenter.mq;
 
import org.springframework.amqp.rabbit.annotation.rabbithandler;
import org.springframework.amqp.rabbit.annotation.rabbitlistener;
import org.springframework.stereotype.component;
 
@component
@rabbitlistener(queues = amqpconfig.hello)
public class hellosubscriber {
 @rabbithandler
 public void process(string hello) {
  system.out.println("hellosubscriber : " + hello);
 }
}

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對服務(wù)器之家的支持。

原文鏈接:http://www.cnblogs.com/lori/p/9739130.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: h片在线| 日本在线视频免费观看 | 久久黄网 | 久久久精品亚洲 | 午夜国产视频 | 午夜视频在线免费观看 | 免费在线看a | 免费看国产片在线观看 | 亚洲欧美精品一区二区 | 久久99精品久久久久久国产越南 | 成人小视频在线观看 | 最近中文字幕mv免费高清在线 | 日韩一二 | 久久色视频 | 久久久久亚洲 | 精品久久国产老人久久综合 | 国产丝袜久久久 | 成人精品视频在线 | 国产精品久久一区二区三区 | 亚洲人成网站b2k3cm | 日韩黄色片免费看 | 色九区| 一区二区三区不卡视频 | 亚洲精品久久 | 国产一区网站 | 欧美日韩一区二区在线观看 | 国产精品美女久久久久久久久久久 | 精品久久一区二区三区 | 成人网av | 黄色一级片免费 | 韩国一区二区视频 | 久久久高清 | 日韩亚洲一区二区 | 不卡av一区二区三区 | 日韩精品影院 | 激情综合五月网 | 色黄网站 | 亚州国产 | 国产欧美日本 | 亚洲一区二区在线播放 | 情一色一乱一欲一区二区 |