[libanyevent-rabbitmq-perl] 90/151: Support for consuming large messages

Damyan Ivanov dmn at moszumanska.debian.org
Thu Jan 16 11:03:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

dmn pushed a commit to annotated tag debian/1.12-1
in repository libanyevent-rabbitmq-perl.

commit 44f9a2d5f184dab9b8b6dbe0dee939795806ee74
Author: Christopher Masto <chris at masto.com>
Date:   Wed Jun 29 10:41:03 2011 -0400

    Support for consuming large messages
    
    Messages over a certain size may contain multiple body frames: [header] [body] [body] …
    AnyEvent::RabbitMQ was assuming the existence of only a single body frame.  Use the body size header to ensure all data is received before running the callback.
---
 lib/AnyEvent/RabbitMQ/Channel.pm | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/AnyEvent/RabbitMQ/Channel.pm b/lib/AnyEvent/RabbitMQ/Channel.pm
index 64df547..f993199 100644
--- a/lib/AnyEvent/RabbitMQ/Channel.pm
+++ b/lib/AnyEvent/RabbitMQ/Channel.pm
@@ -624,6 +624,7 @@ sub _push_read_header_and_body {
     my $self = shift;
     my ($type, $frame, $cb, $failure_cb,) = @_;
     my $response = {$type => $frame};
+    my $body_size = 0;
 
     $self->{_content_queue}->get(sub{
         my $frame = shift;
@@ -638,17 +639,30 @@ sub _push_read_header_and_body {
         ) if !$header_frame->isa('Net::AMQP::Protocol::Basic::ContentHeader');
 
         $response->{header} = $header_frame;
+        $body_size = $frame->body_size;
     });
 
-    $self->{_content_queue}->get(sub{
+    my $body_payload = "";
+    my $next_frame; $next_frame = sub {
         my $frame = shift;
 
         return $failure_cb->('Received data is not body frame')
             if !$frame->isa('Net::AMQP::Frame::Body');
 
-        $response->{body} = $frame;
-        $cb->($response);
-    });
+        $body_payload .= $frame->payload;
+
+        if (length($body_payload) < $body_size) {
+            # More to come
+            $self->{_content_queue}->get($next_frame);
+        }
+        else {
+            $frame->payload($body_payload);
+            $response->{body} = $frame;
+            $cb->($response);
+        }
+    };
+
+    $self->{_content_queue}->get($next_frame);
 
     return $self;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libanyevent-rabbitmq-perl.git



More information about the Pkg-perl-cvs-commits mailing list