Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 89a1007

Browse files
6
1 parent 1d5132a commit 89a1007

5 files changed

Lines changed: 220 additions & 12 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
---
22
layout: post
3-
title: RabbitMQ_learn
3+
title: RabbitMQ的一些业务使用总结
44
categories: [blog]
55
tags: [RabbitMQ]
66
description:
77
---
88

9-
RabbitMQ_learn
9+
# 一些业务使用RabbitMQ的总结
1010

11-
1. R.Connection create TCP connection, channels shares a connection. TCP connection is costly.
11+
[TOC]
1212

13-
2. flow
13+
## Core理解
1414

15-
```flow
16-
st=>start: Producer
17-
e=>end: Consumer
18-
opExchange=>operation: Exchange
19-
opBlinding=>operation: Blinding
20-
opQueue=>operation: Queue
21-
st->opExchange->opBlinding->opQueue->e
22-
```
15+
理解几个概念,Queue是根据Bingdings规则绑定到Exchange的,消息是发布到Exchange上的,服务器决定消息投递到哪个队列。
2316

17+
### flow
18+
19+
```flow
20+
st=>start: Producer
21+
e=>end: Consumer
22+
opExchange=>operation: Exchange
23+
opBlinding=>operation: Blinding
24+
opQueue=>operation: Queue
25+
st->opExchange->opBlinding->opQueue->e
26+
```
2427

2528
basic.consumer: 订阅,消费后最近的消息后**自动接收**下一条消息。
2629

@@ -30,3 +33,90 @@ Consumer获得消息需要返回basic.ack,一般采用auto_ack。
3033

3134
basic.reject允许Consumer拒绝消息。basic.reject=true?重发:删除
3235

36+
### connection&channel
37+
38+
许多channels共享一个TCP connection。单个channel的生产消费能力就十分强了,而且channel的创建代价不高,无需维护连接池,最多只需要维护connection的连接池即可。
39+
40+
关于connection&channel的双层连接池的设计比较没用,并且因为channel的自动重连机制而难以维护,我实现过,压测结果发现没啥卵用问题不少。
41+
42+
### Bindings
43+
44+
```
45+
channel.queue_bind(exchange=exchange_name,
46+
queue=queue_name,
47+
routing_key='city.boardcast')
48+
```
49+
50+
51+
52+
### Exchange
53+
54+
#### direct exchange
55+
56+
可以通过routingKey匹配投递到对应队列。
57+
58+
如果相同名称的routingKey绑定了多个队列的话就相当于fanout了。
59+
60+
#### fanout exchange
61+
62+
只能广播用
63+
64+
#### topic exchange
65+
66+
应用最为广泛的。该exchange与direct exchange基本相同,区别是可以匹配规则。
67+
68+
譬如说,CityProducer生产了`routing_key='city.boardcast'`,StateProducer生产了`routing_key='state.boardcast'`,如果我现在有一个queue=boardcast_queue需要接受city和state所有的消息,只需要`routing_key='*.boardcast'`
69+
70+
```
71+
channel.queue_bind(exchange=exchange_name,
72+
queue=boardcast_queue,
73+
routing_key='*.boardcast')
74+
```
75+
76+
routing_key按照`.`来分割,匹配任意字符`*`,匹配所有routing_key`#`
77+
78+
### VHOST
79+
80+
顾名思义——虚拟服务器,与RMQ服务器关系类似于OS和虚拟机。
81+
82+
vhost之间绝对隔离,不同的vhost里的exchange、queue不能通行。所以对于一个业务来说,建立一个vhost保证了安全性。
83+
84+
默认vhost是`/`
85+
86+
## Consumer
87+
88+
消费就两种,一种推一种拉,推就是走订阅模式,mq通过长连接推到客户端;拉就是客户端不对的rpc到server去polling。
89+
90+
### 推示例
91+
92+
```java
93+
Connection connection = factory.newConnection();
94+
Channel channel = connection.createChannel();
95+
channel.basicQos(1);
96+
channel.exchangeDeclare(getExchange(), "topic", true);
97+
channel.queueBind(getQueueName(), getExchange(), getRoutingKey());
98+
QueueingConsumer consumer = new QueueingConsumer(channel);
99+
channel.basicConsume(getQueueName(), true, consumer);
100+
QueueingConsumer.Delivery delivery = null;
101+
try {
102+
delivery = consumer.nextDelivery();
103+
} catch (Exception ex) {
104+
logger.error("next delivery failed: ", ex);
105+
if (ex instanceof InterruptedException ||
106+
ex instanceof ShutdownSignalException ||
107+
ex instanceof ConsumerCancelledException) {
108+
consumer = null;
109+
}
110+
continue;
111+
}
112+
//do with delivery.getBody()
113+
```
114+
115+
###
116+
117+
```
118+
channel.basicGet("queue_name", autoAck=true)
119+
```
120+
121+
退的好处是及时消费,拉的好处是可以在客户端控制速率,避免尖峰把服务打挂。
122+

_posts/2016-09-11-Family_medical_record.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,38 @@ description:
3030

3131
不怎么用
3232

33+
#### 透明质酸
3334

35+
冈本有款透明质酸广受好评,btw玻尿酸就是透明质酸。
36+
37+
1/500是爽肤水
38+
1/100是面膜
39+
40+
####
41+
42+
## 唇膏
43+
44+
Blistex的小蓝罐润唇膏,一瓶能用一年,不用尝试其他牌子了。
45+
46+
#### 原理
47+
48+
隔水层保湿。
49+
50+
#### 实现
51+
52+
##### 蜂蜡橄榄油唇膏
53+
54+
- 橄榄油 25ml
55+
56+
- 白蜂蜡 10g
57+
58+
- VE油 4滴
59+
60+
##### 凡士林唇膏:
61+
62+
- 凡士林10g
63+
64+
- 香水喷7-10下
3465

3566
## 美白
3667

@@ -55,6 +86,10 @@ description:
5586

5687

5788

89+
### AA2G
90+
91+
### 曲酸
92+
5893
# 用药
5994

6095
## 除痘痘

_posts/2017-01-09-Bash-Shell.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ fi
108108

109109
跟Python差不多。
110110

111+
示例:
112+
113+
```shell
114+
#!/bin/bash
115+
export KEEPER_DIR="ature/hell"
116+
successFunc(){
117+
echo $KEEPER_DIR" is current success";
118+
}
119+
failFunc(){
120+
echo $KEEPER_DIR" is current error";
121+
}
122+
#注意空格
123+
if [[ $KEEPER_DIR == master || $KEEPER_DIR == release || $KEEPER_DIR == develop || $KEEPER_DIR =~ feature.* ]];then successFunc; else failFunc; fi
124+
```
125+
126+
127+
111128
### while
112129

113130
```shell

_posts/2017-03-06-Cross_domain.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
layout: post
3+
title: 浏览器跨域问题
4+
categories: [blog]
5+
tags: [FE]
6+
description: fe
7+
---
8+
9+
# 浏览器跨域问题
10+
11+
## 产生原因
12+
13+
Ajax就是使用js构建的异步网络请求。
14+
15+
```
16+
function success(text) {
17+
var textarea = document.getElementById('test-response-text');
18+
textarea.value = text;
19+
}
20+
21+
function fail(code) {
22+
var textarea = document.getElementById('test-response-text');
23+
textarea.value = 'Error code: ' + code;
24+
}
25+
26+
var request = new XMLHttpRequest(); // 新建XMLHttpRequest对象
27+
28+
request.onreadystatechange = function () { // 状态发生变化时,函数被回调
29+
if (request.readyState === 4) { // 成功完成
30+
// 判断响应结果:
31+
if (request.status === 200) {
32+
// 成功,通过responseText拿到响应的文本:
33+
return success(request.responseText);
34+
} else {
35+
// 失败,根据响应码判断失败原因:
36+
return fail(request.status);
37+
}
38+
} else {
39+
// HTTP请求还在继续...
40+
}
41+
}
42+
43+
// 发送请求:
44+
request.open('GET', '/api/categories');
45+
request.send();
46+
47+
alert('请求已发送,请等待响应...');
48+
```
49+
50+
上述代码中`request.open('GET', '/api/categories')`中URL使用的是相对路径。默认情况下,JavaScript在发送AJAX请求时,URL的域名必须和当前页面完全一致。完全一致的意思是,域名要相同(`www.example.com``example.com`不同),协议要相同(`http``https`不同),端口号要相同(默认是`:80`端口,它和`:8080`就不同)。
51+
52+
## 解决办法
53+
54+
1. ### Flash
55+
56+
2. ### Proxy transmit
57+
58+
3. ### JSONP
59+
60+
只能用GET请求,利用浏览器允许跨域引用JavaScript资源,即直接获得含有数据结果的js。所以,只要把URL当成js路径,服务端将data封到js里面返回就可以。
61+
62+
[示例](http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html)
63+
64+
ajax的核心是通过XmlHttpRequest获取非本页内容,而jsonp的核心则是动态添加<script>标签来调用服务器提供的js脚本。
65+
66+

0 commit comments

Comments
 (0)