Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

message in queue impact by another message #129

Open
liu11hao11 opened this issue Jun 2, 2017 · 0 comments
Open

message in queue impact by another message #129

liu11hao11 opened this issue Jun 2, 2017 · 0 comments

Comments

@liu11hao11
Copy link

liu11hao11 commented Jun 2, 2017

1.I send a message to my queue,I called this message “A”,In my code ,"A" is not unacked, and then I requeue "A",handle "A" takes a lot time.
2.in the same time,another Message "B" comes, and acked.
3.then I receive the requeue meassge ,but "B" appear in my console.not "A"

I was so confused,
my code goes here:

const createContext = require('rabbit.js').createContext;

var context = createContext(config.QUEUE_LOCATION);

context.on('ready', () => {

    var sub = context.socket('WORKER', { prefetch: 1 });
    sub.setEncoding('utf8');
    sub.on('data', (message) => {

        handle(sub,message)
    });
    const cpus = require('os').cpus();
    async.forEachOf(cpus, (value, i, cb) => {
        sub.connect(config.QUEUE_NAME, function () {
            console.log(i, 'connected');
            cb();
        });
    }, (err) => {
        if (err)
            console.log(new Error(err), 'rabbitmq sub.connect error');
    });
});
async function handle(sub,message){
    console.log('received:', message);
    var msg = {};
    const TAG = "handle-msg";
    console.time(TAG);
    message=JSON.parse(message)
    if (message.test) {
        console.log("ack")
        sub.ack();
        return;
    }
    console.log('requeue');
    await sleep(10000);
    sub.requeue();
    return;

}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms))
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant