Comparing version 3.5.1 to 3.6.0
3.6.0 / 2019-04-15 | ||
================== | ||
**features** | ||
* [[`2cd16be`](http://github.com/ali-sdk/ali-ons/commit/2cd16bed4608ca4235ad9eb5c211b9aad090a411)] - feat: support namespace (#75) (zōng yǔ <<gxcsoccer@users.noreply.github.com>>) | ||
**fixes** | ||
* [[`0176223`](http://github.com/ali-sdk/ali-ons/commit/0176223b3fdd3a2e5a219fb02b03552764951588)] - fix: retry should process by broker (#73) (Hongcai Deng <<admin@dhchouse.com>>) | ||
**others** | ||
* [[`35f9341`](http://github.com/ali-sdk/ali-ons/commit/35f934174077e6835284ca5cbebb3e171122fd11)] - chore: update test config (#74) (zōng yǔ <<gxcsoccer@users.noreply.github.com>>) | ||
3.5.1 / 2019-04-12 | ||
@@ -3,0 +15,0 @@ ================== |
@@ -14,5 +14,4 @@ 'use strict'; | ||
unitMode: false, | ||
// https://help.aliyun.com/document_detail/102895.html 阿里云产品更新,支持实例化 | ||
// nameSrv: '112.124.141.191:80', | ||
// 阿里云自创建实例,需要 ns 前缀 | ||
namespace: '', | ||
// 公有云生产环境:http://onsaddr-internal.aliyun.com:8080/rocketmq/nsaddr4client-internal | ||
@@ -23,2 +22,4 @@ // 公有云公测环境:http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet | ||
onsAddr: 'http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet', | ||
// https://help.aliyun.com/document_detail/102895.html 阿里云产品更新,支持实例化 | ||
nameSrv: 'onsaddr.mq-internet-access.mq-internet.aliyuncs.com:80', | ||
onsChannel: 'ALIYUN', // CLOUD, ALIYUN, ALL | ||
@@ -67,2 +68,6 @@ }; | ||
get namespace() { | ||
return this.options.namespace; | ||
} | ||
/** | ||
@@ -69,0 +74,0 @@ * 将实例名修改为进程号 |
@@ -101,2 +101,5 @@ 'use strict'; | ||
get consumerGroup() { | ||
if (this.namespace) { | ||
return `${this.namespace}%${this.options.consumerGroup}`; | ||
} | ||
return this.options.consumerGroup; | ||
@@ -184,2 +187,7 @@ } | ||
subscribe(topic, subExpression, handler) { | ||
// 添加 namespace 前缀 | ||
if (this.namespace && !topic.startsWith(this.namespace)) { | ||
topic = `${this.namespace}%${topic}`; | ||
} | ||
if (arguments.length === 2) { | ||
@@ -277,2 +285,4 @@ handler = subExpression; | ||
utils.resetRetryTopic(msg, this.consumerGroup); | ||
try { | ||
@@ -752,7 +762,8 @@ await handler(msg, mq, pq); | ||
newMsg.retryTopic = msg.topic; | ||
newMsg.properties[MessageConst.PROPERTY_MAX_RECONSUME_TIMES] = this.options.maxReconsumeTimes; | ||
// 这里需要加 1,因为如果 maxReconsumeTimes 为 1,那么这条 retry 消息发出去始终不会被重新投递了 | ||
newMsg.properties[MessageConst.PROPERTY_MAX_RECONSUME_TIMES] = String(this.options.maxReconsumeTimes + 1); | ||
} | ||
newMsg.properties[MessageConst.PROPERTY_RECONSUME_TIME] = String(msg.reconsumeTimes + 1); | ||
newMsg.delayTimeLevel = 3 + msg.reconsumeTimes; | ||
newMsg.delayTimeLevel = 0; | ||
await (await MQProducer.getDefaultProducer()).send(newMsg); | ||
@@ -759,0 +770,0 @@ } |
'use strict'; | ||
const chalk = require('chalk'); | ||
const Logger = require('egg-logger').Logger; | ||
const ConsoleTransport = require('egg-logger').ConsoleTransport; | ||
const duartionRegexp = /([0-9]+ms)/g; | ||
// eslint-disable-next-line no-useless-escape | ||
const categoryRegexp = /(\[[\w\-_.:]+\])/g; | ||
const httpMethodRegexp = /(GET|POST|PUT|PATH|HEAD|DELETE) /g; | ||
const logger = new Logger(); | ||
logger.set('console', new ConsoleTransport({ | ||
level: 'DEBUG', | ||
formatter(meta) { | ||
let msg = meta.date + ' ' + meta.level + ' ' + meta.pid + ' ' + meta.message; | ||
if (!chalk.supportsColor) { | ||
return msg; | ||
} | ||
if (meta.level === 'ERROR') { | ||
return chalk.red(msg); | ||
} else if (meta.level === 'WARN') { | ||
return chalk.yellow(msg); | ||
} | ||
msg = msg.replace(duartionRegexp, chalk.green('$1')); | ||
msg = msg.replace(categoryRegexp, chalk.blue('$1')); | ||
msg = msg.replace(httpMethodRegexp, chalk.cyan('$1 ')); | ||
return msg; | ||
module.exports = { | ||
info() {}, | ||
warn(...args) { | ||
console.warn(...args); | ||
}, | ||
})); | ||
module.exports = logger; | ||
error(...args) { | ||
console.error(...args); | ||
}, | ||
debug() {}, | ||
}; |
@@ -56,2 +56,5 @@ 'use strict'; | ||
get producerGroup() { | ||
if (this.namespace) { | ||
return `${this.namespace}%${this.options.producerGroup}`; | ||
} | ||
return this.options.producerGroup; | ||
@@ -194,2 +197,6 @@ } | ||
if (this.namespace && !msg.topic.startsWith(this.namespace)) { | ||
msg.topic = `${this.namespace}%${msg.topic}`; | ||
} | ||
const maxTimeout = this.options.sendMsgTimeout + 1000; | ||
@@ -196,0 +203,0 @@ const timesTotal = 1 + this.options.retryTimesWhenSendFailed; |
@@ -19,2 +19,5 @@ 'use strict'; | ||
// V3_4_9 支持设置重试的 maxReconsumeTimes | ||
const MQ_VERSION = 121; | ||
const buf = new ByteBuffer({ size: bytes('1m') }); | ||
@@ -49,3 +52,3 @@ | ||
get version() { | ||
return 78; | ||
return MQ_VERSION; | ||
} | ||
@@ -52,0 +55,0 @@ |
{ | ||
"name": "ali-ons", | ||
"version": "3.5.1", | ||
"version": "3.6.0", | ||
"description": "Aliyun Open Notification Service Client", | ||
@@ -14,4 +14,4 @@ "main": "lib/index.js", | ||
"test": "npm run lint && npm run test-local", | ||
"test-local": "egg-bin test", | ||
"cov": "TEST_TIMEOUT=60000 egg-bin cov", | ||
"test-local": "TEST_TIMEOUT=120000 egg-bin test", | ||
"cov": "TEST_TIMEOUT=120000 egg-bin cov", | ||
"ci": "npm run autod -- --check && npm run pkgfiles && npm run lint && npm run cov", | ||
@@ -41,5 +41,3 @@ "contributors": "contributors -f plain -o AUTHORS" | ||
"bytes": "^3.1.0", | ||
"chalk": "^2.4.2", | ||
"debug": "^4.1.1", | ||
"egg-logger": "^2.4.1", | ||
"is-type-of": "^1.2.1", | ||
@@ -46,0 +44,0 @@ "long": "^4.0.0", |
@@ -39,2 +39,3 @@ ali-ons | ||
consumerGroup: 'your-consumer-group', | ||
// namespace: '', // aliyun namespace support | ||
// isBroadcast: true, | ||
@@ -54,3 +55,2 @@ }); | ||
'use strict'; | ||
const co = require('co'); | ||
const httpclient = require('urllib'); | ||
@@ -65,2 +65,3 @@ const Producer = require('ali-ons').Producer; | ||
producerGroup: 'your-producer-group', | ||
// namespace: '', // aliyun namespace support | ||
}); | ||
@@ -89,3 +90,3 @@ | ||
- [ons secure data](https://sharelock.io/1/JcYdigaQDDbJbFiuUAue6LkmT2pDLAdvWcYZE4A-WKw.Tfy1NC/ry_QLizOWLO_B1_l2OnW7_jRoOH8Avm52oHDLkI9Jq_z5P8va5/GVODvZrDgZL1VvAdzyMO7cKULW25vDle_vsXhPSJdQXul-QM4b/tiv0cYLrLpw9FRJYtT_fcSasEcdtt776WqJ_R1ftC9eg7vtsxD/-CPmBShnD5SG_cEVVZSQuv_geF63l_m6rXPbhKBhHJ3mKGF0_2/yAlpQHVdZA6N5iFlvcMI0ogmXNqkqBGl6yE3-cIqSRZqLSDUd4/EPMhwInVHlL4O9BwM5wYDMT17hiYIaQsXvsGCywGEdjEpLKZdV/7ir9t8RBov0q0FgpcuMrJTvMyQ5dyeoDGzyLm5QTjL8Ty7gqa_/.tFnt_NoGsl3YifWa5BhLnA) | ||
- [ons secure data](https://sharelock.io/1/UM02CJiYyhXiZDOn1nhX0iqPqMIQtdwI_T5BY3F-tHs.d8-ycA/01veKH9kgAuFuKCqlVPzGsyPWJ8mQLaKPJjjcB9tpdbvi9L6XQ/IgqDvAdVDMzV9lK2gQzyAj7q-CNk8-1tWrLmdqMV0oJ5qgky40/HgpZyKKDfOGAcyqQ20RUdRgCLRWqF8LUUko0uDl_L-ATNOsi5z/W2bsvBc8tAoqSwNR7u2Sqe6XkNmD98s3UQOK-6T8--VwTbHzcG/dwkHwie3EkGB-TbiMnbRh7_5A-DaOTCtALP3xvl4G0XKxuOriC/2yfuPp7WRucTAoqx2STO5Hv3MZEhh3IXf7YiOQ8pWDDqjLuQSY/_irqzYyeseY9m106ksMUq3-yS_qkBRIuoyL-hHk9ZRhGppsdA5/Dw4Pjg.fmNP3aFkLnvPuhlPRwNcng) | ||
@@ -92,0 +93,0 @@ ## License |
151790
15
4140
92
- Removedchalk@^2.4.2
- Removedegg-logger@^2.4.1
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcircular-json-for-egg@1.0.0(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddepd@2.0.0(transitive)
- Removedegg-errors@2.3.2(transitive)
- Removedegg-logger@2.9.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedms@2.0.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsupports-color@5.5.0(transitive)