AS3 AMQP - fork to add Publish/Subscribe patterns

9 views
Skip to first unread message

Peter

unread,
Aug 7, 2008, 10:07:25 AM8/7/08
to as3-amqp-user
Hi guys,

Last week I forked the AS3 AMQP project to incorporate Publish and
Subscribe classes. The work can be viewed here:

http://github.com/pkieltyka/as3-amqp

New files:

1. BasicMessageEvent class: used to accept delivered messages based on
a binding key
http://github.com/pkieltyka/as3-amqp/tree/master/src/org/amqp/patterns/BasicMessageEvent.as

2. PublishClient interface: method to send an object based on a
particular key (ie. topic binding key)
http://github.com/pkieltyka/as3-amqp/tree/master/src/org/amqp/patterns/PublishClient.as

3. SubscribeClient interface: methods to subscribe/unsubscribe based
on a particular topic key and pass a callback function to be used for
consuming messages
http://github.com/pkieltyka/as3-amqp/tree/master/src/org/amqp/patterns/SubscribeClient.as

4. PublishClientImpl: implements the methods from PublishClient
http://github.com/pkieltyka/as3-amqp/tree/master/src/org/amqp/patterns/impl/PublishClientImpl.as

5. SubscribeClientImpl: implements the methods from SubscribeClient
and BasicConsumer
http://github.com/pkieltyka/as3-amqp/tree/master/src/org/amqp/patterns/impl/SubscribeClientImpl.as

I've tested it and it works great. However, the SubscribeClient /
SubscribeClientImpl only works for a single topic at the moment. I
have to implement a hash of the various subscribed topics (keys) and
their associated callback functions. When the client unsubscribes it
will purge the replyQueue and remove the event listener that consumes
messages. One thing to mention is for each subscribed topic, a new
replyQueue is created automatically.

From my testing, there currently is an issue where the two clients
make two connections when calling super(c) (the AbstractDelegate
constructor). We could modify the constructor in AbstractDelegate to
check if a connection exists and then to simply return, but this is
Ben's decision of how he intends the library to work.

Cheers,

Peter

Peter

unread,
Aug 19, 2008, 10:37:55 AM8/19/08
to as3-amqp-user
Hey there,

So I've had some progress on the pattern following my post above.

The repository can be accessed: http://github.com/pkieltyka/as3-amqp

Changes:
1. PublishClientImpl
- Publishes messages to a topic based on the key provided. It queues
messages prior to receiving a requestOk from the server.

2. SubscribeClientImpl
- Subscribes to one or more topics and creates a listener for
consuming messages to a callback function. It queues subscription
requests until a requestOk is received from the server.

3. PublishSubscribeClientImpl
- This is a combined version of 1&2 above, for two reasons. One, the
clients extend the AbstractDelegate class which opens a new connection
each time, this will require an intermediary state for the connection
like CONNECTING so other clients do not attempt to start a connection
while one is connecting. Two, if the client subscribes to a topic, and
immediately following a call is made to publish to that topic on some
consumption function, the message will be sent out before the
subscription is made in most cases, and the message will not be
consumed. The solution is to buffer the messages specific to a topic.
- Also note that you can use this client without subscribing to any
topic
- An unsubscribe method is available to purge the bound replyQueue for
the topic

4. PublishSubscribeClientTest
- Test suite that demonstrates the functionality of
PublishSubscribeClientImpl


TODO / Further exploration:
- Ben Hood (creator of this library) mentioned that request/requestOk
is being phased out of rabbit, all of the clients wait for a requestOk
before making requests to the server. This is how I've left it for the
time being until AbstractDelegate is updated by Ben.
- Multiple invocations to client constructors (via an intermediary
CONNECTING state)
- Optimize the file size of overall library to decrease its 304kb
weight down to something reasonable. For one, I noticed the core
library depends on flexunit.swc, which weighs in at 400kb itself.
Perhaps looking at removing that dependency will cut some fat, in
particular the ArrayList class is used and should be substituted with
something already available.

Cheers,

Peter

Ben Hood

unread,
Aug 20, 2008, 9:08:39 AM8/20/08
to as3-am...@googlegroups.com
Peter,

Great work! I have made most of my comments via the github comment
mechanism: http://github.com/pkieltyka/as3-amqp/comments

As I am using this for the first time, we will have to see whether it
is more useful that just free form emails.

On Tue, Aug 19, 2008 at 3:37 PM, Peter <peter.k...@gmail.com> wrote:
> Changes:
> 1. PublishClientImpl
> - Publishes messages to a topic based on the key provided. It queues
> messages prior to receiving a requestOk from the server.

Because realms have now been removed from the RabbitMQ default branch,
this can be removed (see inline comment for more detail).

> 2. SubscribeClientImpl
> - Subscribes to one or more topics and creates a listener for
> consuming messages to a callback function. It queues subscription
> requests until a requestOk is received from the server.

See above for comment about realms.

>
> 3. PublishSubscribeClientImpl
> - This is a combined version of 1&2 above, for two reasons. One, the
> clients extend the AbstractDelegate class which opens a new connection
> each time, this will require an intermediary state for the connection
> like CONNECTING so other clients do not attempt to start a connection
> while one is connecting. Two, if the client subscribes to a topic, and
> immediately following a call is made to publish to that topic on some
> consumption function, the message will be sent out before the
> subscription is made in most cases, and the message will not be
> consumed. The solution is to buffer the messages specific to a topic.

Hmmm, I can see where you are coming from, but I wonder if there is a
cleaner way to do this. I will have to look into it.

> - Also note that you can use this client without subscribing to any
> topic
> - An unsubscribe method is available to purge the bound replyQueue for
> the topic

This can be achieved by autodelete, IMHO, see inline comment.

> 4. PublishSubscribeClientTest
> - Test suite that demonstrates the functionality of
> PublishSubscribeClientImpl
>
>
> TODO / Further exploration:
> - Ben Hood (creator of this library) mentioned that request/requestOk
> is being phased out of rabbit, all of the clients wait for a requestOk
> before making requests to the server. This is how I've left it for the
> time being until AbstractDelegate is updated by Ben.

This can now be deleted :-)

Whether you do it and I merge, or I do it and you resync is your choice.

> - Multiple invocations to client constructors (via an intermediary
> CONNECTING state)

Not sure, see comment above.

> - Optimize the file size of overall library to decrease its 304kb
> weight down to something reasonable. For one, I noticed the core
> library depends on flexunit.swc, which weighs in at 400kb itself.
> Perhaps looking at removing that dependency will cut some fat, in
> particular the ArrayList class is used and should be substituted with
> something already available.

This is an excellent idea.

Ben

Ben Hood

unread,
Aug 20, 2008, 9:12:42 AM8/20/08
to as3-am...@googlegroups.com
Peter,

On Thu, Aug 7, 2008 at 3:07 PM, Peter <peter.k...@gmail.com> wrote:

> From my testing, there currently is an issue where the two clients
> make two connections when calling super(c) (the AbstractDelegate
> constructor). We could modify the constructor in AbstractDelegate to
> check if a connection exists and then to simply return, but this is
> Ben's decision of how he intends the library to work.

Yes, this is good point, which I'll have to think about what is the
most elegant solution.

Stupidly, I've only got my AS3 environment set up on my laptop which
is currently sitting at Apple in the repair section :-(

So I'll get FB going on my desktop :-)

Ben

Reply all
Reply to author
Forward
0 new messages