[Q] need help debugging MQ.dispatch exception

19 views
Skip to first unread message

Chuck Remes

unread,
Dec 28, 2009, 4:39:03 PM12/28/09
to amq...@googlegroups.com
I'm getting a TypeError when trying to define a direct exchange. Here
is the code that causes it along with the exact error message.

try
{
// name is a CPString which is really just a String with a few more
method calls
_session_exchange = MQ.direct(name);
}
catch(err)
{
console.log(err);
}

TypeError: Result of expression 'this.api[args.shift()]' [undefined]
is not an object. (file:///Users/cremes/Documents/development/javascript/Pilot2/lib/amqp-js/javascripts/mq.js:305
)


While debugging this, the line in question that chokes (mq.js:305) is
this:

return this.api[args.shift()].apply(this.api, args);

At the time of the call, the args array has 3 elements:

0: "exchange"

1:dictionary object
{ exchange: "session", type: "direct"}

2:isa Object
don't know what this is.

Based on my reading and deconstruction of the javascript, it is trying
to retrieve the "exchange" index of the this.api object and call it
with itself and the arguments array (now reduced by 1 element).

Something in there is undefined but I can't see what it is. I tried to
"step into" that call, but it must have thrown that exception right
away.

Any suggestions?

cr

Chuck Remes

unread,
Dec 28, 2009, 6:01:01 PM12/28/09
to amq...@googlegroups.com

Enabling logging in the MQ.configure block hasn't provided very much
more information. If I provide a MQ.on("load") function in my html
script, it prints to the console that it was loaded. I never see any
other messages in the log from this lib.

This leads me to think that something is going awry with the
ActionScript stuff that needs to be loaded. The call to
this.api[args.shift()].apply(this.api, args) is probably trying to hit
the ActionScript code. I can see that there is a line in the
constructor that sets up the call to "exchange":

ExternalInterface.addCallback("exchange", api_declare_exchange);

I am now loading amqp-debug.swf but it hasn't put out any messages
either about security exceptions or other exceptions. I am guessing
that the flash movie isn't really loading correctly.

I have confirmed that all of the flash files are set to be "trusted"
using the Flash Security Manager. I chose my entire javascripts
folder; according to the docs it should trust all content in the
subdirectories too.

I'm still stuck.

cr

Dan Simpson

unread,
Dec 28, 2009, 7:23:36 PM12/28/09
to amq...@googlegroups.com, amq...@googlegroups.com
Hmm,

I will check this out tonight and let you know. Have you been able to
get other exchanges working?

--Dan

Sent from my iPhone

> --
>
> You received this message because you are subscribed to the Google
> Groups "amqp-js" group.
> To post to this group, send email to amq...@googlegroups.com.
> To unsubscribe from this group, send email to amqp-js+u...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/amqp-js?hl=en
> .
>
>

Chuck Remes

unread,
Dec 28, 2009, 7:53:29 PM12/28/09
to amq...@googlegroups.com
Switching from MQ.direct to MQ.fanout gives the same result.

This stuff works in the examples but in my own project it is failing. Like I mentioned in an earlier email, I think it is load path issues but I have no idea how to confirm that.

cr

Chuck Remes

unread,
Dec 29, 2009, 11:08:21 AM12/29/09
to amq...@googlegroups.com
Continuing the debugging...

When I make the call to MQ.direct, I have traced through all of the
calls. I can confirm that the call to the ActionScript "exchange"
function (mapped to api_declare_exchange) is returning a null/
undefined value. This null value gets saved in the
this.exchanges[name] array, I think. It is hard to tell because in the
browser javascript debugger it shows the this.exchanges value as an
Object with no elements (i.e. can't examine its contents/fields).

Anyway, the stack unwinds and then executes the "catch" block. I'm
guessing an exception is thrown when making the AS call so
this.exchanges is never really assigned as the stack unwinds. I wish I
could tell why the AS call is throwing an exception. I am using the
amqp-debug.swf but it hasn't produced any more output.

Also, I modified the callback function in the swfobject.embedSWF call
to print out the load status. The event.success value is true, so the
movie *is* loading successfully so I no longer think it is a load path
issue.

I think I have gone as far as I can. I don't have a flash authoring
environment otherwise I would modify the AS and generate new flash
movies with additional debugging.

cr

Dan Simpson

unread,
Dec 29, 2009, 11:43:51 AM12/29/09
to amq...@googlegroups.com
In front of the computer now.

Please send the code used in your script that is configuring MQ, setting up the exchanges, and also the embed code.

I am going to test direct and fanout exchanges, which should work.

--Dan

Chuck Remes

unread,
Dec 29, 2009, 12:02:04 PM12/29/09
to amq...@googlegroups.com
Dan,

I am pretty sure that I figured it out. It's a race condition related to the AS Connection object and calls to declare exchanges/queues, etc.

There were two problems.

1. It was auto-connecting to the default destination (amqp.peermessaging.com) even though I need it to connect to localhost. My call to MQ.configure was coming too late. Setting a new host and calling MQ.connect directly didn't help. I fixed this in #2.

2. I moved my MQ.configure call into the HTML file that embeds the flash movie. It now autoConnects to localhost. However, when I am declaring the direct exchange, the connection has just printed "Handshaking" to the log. The connection is not yet in a ready state.


So, it seems like calls to MQ.direct/fanout/topic/queue should check to see if the connection is "ready" otherwise return an error. I would actually prefer an MQ.ready call to return a boolean then I can handle the checking myself and set timeouts on my end to retry, etc.

What a learning opportunity!

cr

Chuck Remes

unread,
Dec 29, 2009, 12:04:45 PM12/29/09
to amq...@googlegroups.com
Use this gist instead (linebreaks were goofed up on the prior one).


cr

Dan Simpson

unread,
Dec 29, 2009, 12:20:21 PM12/29/09
to amq...@googlegroups.com
This sounds right.  From a high level it seems like a side effect of mutability in an evented environment.

I am going to refactor what I have to accept the new adaptors that I am releasing, along with better execution control.  Currently, there are mechanisms to prevent certain actions from happening before they should.

Eg:  MQ.queue("auto").bind("mytopic").callback(...)

When that is called, a queue is declared, a subscription is declared, an exchange is declared, and a binding is declared.  So the high level abstraction must have some smarts to ensure the proper order of execution.

Anyways,  those commands should queue up and execute on connection, but I failed to cover all the bases.

Keep an eye on the github lib for updates.

I am on vacation so I will be spending some time on my OSS stuff.

--Dan

Chuck Remes

unread,
Dec 29, 2009, 12:25:09 PM12/29/09
to amq...@googlegroups.com
Okay, that all sounds fine. In the meantime I'm going to write a little patch to give myself a MQ.ready function so I can make some more progress on the rest of my application.

Have fun on your vacation. Feel free to hang out in #amqp-js... :)

cr

Chuck Remes

unread,
Dec 29, 2009, 12:41:36 PM12/29/09
to amq...@googlegroups.com
Even waiting for it to be in the Ready state doesn't help. It still
generates that error. Crap.

I have to move on in the short-term just to clear my head. I'll circle
back to this in a day or two.

cr

Reply all
Reply to author
Forward
0 new messages