ali-sdk / ali-ons

Aliyun Open Notification Service Client
MIT License
151 stars 43 forks source link

设置延时发送时,msgId 不一致 #24

Closed clChenLiang closed 5 years ago

clChenLiang commented 6 years ago

使用过程中发送,在 Message含有 delay 参数的情况下,消费者和生产者各自获取到的 msgId 不一致! 测试代码如下:

'use strict';
const co = require('co');
const producer = require('./alionsProducer');

co(function *() {
    for (let i = 0; i < 15; i++) {
        // co(producer.send({ a: 1, b: 2 }, {
        //     delay: i,
        // }));
        let result = yield producer.send({a:i,b:2}, {
            delay: i
        });
        console.log(`第 ${i} 次:${JSON.stringify(result)}`);
    }
});

如果将 delay: i 换成 delay: 0 则接收到的 msgId 一致 send 是对 producer 封装的一个代码:

function *send(content, options) {
        let msg = new Message(
        options.topic || 'Message_test_11',
        options.tag || '*',
        JSON.stringify(content)
    );

    if(options.delay) {
        msg.delayTimeLevel = options.delay;
    }

    let result = yield producer.send(msg);
    return result;
}
clChenLiang commented 6 years ago

可以参考使用: msg.properties.UNIQ_KEY 方法获取

clChenLiang commented 6 years ago

请问 msg.properties 属性是由 阿里云 MQ 服务器确定的吗?

gxcsoccer commented 5 years ago

这个功能我没用过。。

denghongcai commented 5 years ago

延时消息是两条消息

Broker先将消息的 消息的 topic 改成 “SCHEDULE_TOPIC_XXXX”,并把真正的Topic保存在消息的 REAL_TOPIC 属性中。时间到了之后,会将它捞出来,恢复Topic, 并开始写 CommitLog 和 ConsumeQueue。

msg.properties broker 是可能修改的,或者你发送的时候往 msg 里添加也行

gxcsoccer commented 5 years ago

@denghongcai 所以这是正常的了? 这个功能我们貌似没有刻意支持?

denghongcai commented 5 years ago

@gxcsoccer 恩