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

Creating Delayed Queue #7

Closed
dev0x10 opened this issue Apr 17, 2015 · 2 comments
Closed

Creating Delayed Queue #7

dev0x10 opened this issue Apr 17, 2015 · 2 comments

Comments

@dev0x10
Copy link

dev0x10 commented Apr 17, 2015

I wonder how to create delayed message queue. Please take a look on my test case and the result

it('should create send messagee', function (done) {
    rsmq.deleteQueue({'qname': "myqueue"}, function (res) {
      rsmq.createQueue({qname: "myqueue"}, function (err, resp) {
        if (resp === 1 || err.name === 'queueExists') {
          console.log("queue created");
          rsmq.sendMessage({qname: "myqueue", message: "Hello world", "delay": 1}, function (err, resp) {
            if (resp) {
              console.log("message sent");
              console.log("Message sent. ID:" + resp);
              done();
            }
          });
        }
      });
    });
  });

  it('should receive msg', function (done) {
    rsmq.receiveMessage({qname: "myqueue"}, function (err, resp) {
      if (resp.id) {
        console.log("Message received.")
        console.log(resp);
      }
      else {
        console.log(err);
        console.log("No messages for me...");
      }
    });
  });

Result:
queue created
message sent
Message sent. ID:e2mp1o4p90fNowqfWpNbxNdAj2huPIKN
.null
No messages for me...

I didn't put done inside receiveMessage function and wait until timeout but the receiveMessage never triggered again.

@smrchy
Copy link
Owner

smrchy commented Apr 17, 2015

You are creating a queue with the default settings (vt: 30, delay: 0, maxsize: 65536).

Then your are sending a message "Hello world" with delay=1. The delay=1 means this particular message will only appear after 1 second to recipients. As you are trying to receive the message right afterwards it won't be received. Which is correct.

  • Send a message without the "delay" parameter to receive it immediately.
  • Try a receiveMessage after 1+ seconds to receive the message.

@smrchy
Copy link
Owner

smrchy commented Apr 17, 2015

If you want to create a delayed queue where all messages are delayed by n seconds you should use the delay parameter with the createQueue method.

Your queue worker(s) typically poll the queue every second and will receive all messages after the delay has passed

@smrchy smrchy closed this as completed Apr 21, 2015
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

2 participants