Hi Graeme, indeed it's a RPC call to a program in Python. Dan, here is
the relevant code; User makes a HTTP request to /test and the program
sends a message to a python and returns the result to the user.

How do you think it would be the best implementation for this?


var connection = amqp.createConnection({ host: 'localhost' });
var exchange;
var queue;
connection.addListener('ready', function() {

        exchange = connection.exchange('', {
                'type' : 'direct',
                durable : true
        }, function() {

                 queue = connection.queue('incoming', { // DECLARED FIRST TIME
                        durable : true,
                        exclusive : false }, function() {});

        });
 });

...

app.get('/test', loadUser, function(req, res) {

        var ctag;

         queue = connection.queue('incoming', { // DECLARED SECOND TIME
                                                // (if not, throws an
error when requesting it again)
                        durable : true,
                        exclusive : false }, function() {});

         queue.subscribe(function(msg) {
                 console.log("RECEIVED: "+msg)

              queue.unsubscribe(ctag);
                 res.redirect('/home');

           }).addCallback(function(ok) { ctag = ok.consumerTag; });

           exchange.publish('msg_queue', 'functional!', {
              replyTo: 'incoming'
           });

});




On May 17, 6:30 pm, Graeme Foster <[email protected]> wrote:
> This seems a slightly odd way to use a queue - normally you would get the
> queue from the connection and subscribe once, then you get notified of each
> message as it is taken off the queue.
>
> Are you using it for RPC or something? Maybe if you could explain how you
> want to use the queue we could come up with a suggestion.
>
> Cheers,
> G.
>
>
>
>
>
>
>
> On Wednesday, May 16, 2012 4:06:13 PM UTC+1, Cassio Melo wrote:
>
> > Do I really need to instantiate the queue "queue =
> > connection.queue(...)" every time I want to use it?
>
> > Server (node.js):
>
> >  queue = connection.queue('incoming', { // <--- DO I REALLY NEED THAT
> > FOR EVERY REQUEST?
> >         durable : true,
> >         exclusive : false }, function() {});
>
> >  queue.subscribe(function(msg) {
> >       // Unsubcribe here. Maybe there is something like a once
> > listener?
> >      console.log("RECEIVED: "+msg)
> >       //res.send(msg.data);
> >       queue.unsubscribe(ctag);
> >      res.redirect('/home');
>
> >    }).addCallback(function(ok) { ctag = ok.consumerTag; });
>
> >    exchange.publish('msg_queue', 'functional!', {  // request
> >       replyTo: 'incoming'
> >    });
>
> > If queue = connection.queue(...); is instantiated with the server, the
> > first request using the queue is successful, but the following
> > requests throw an error:
>
> > Error: NOT_FOUND - no queue 'incoming' in vhost '/'
> > at Queue._onMethod (/Users/cassiomelo/code/cubix/cubix_nodejs/
> > node_modules/amqp/amqp.js

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to