Skip to content

Commit

Permalink
changes to streamed framing to eliminate extra messages
Browse files Browse the repository at this point in the history
amqp-device.lisp :
 amqp-j-read-chars : add missing end test

commands.lisp :
 change get and deliver to return the headers as well as the content.
 change publish to defer sending the method and header frames until
  the flush operation

device-level.lisp :
 device-flush : send the method and header frames as per the configured
  channel basic instance; do not send any extra termination or
  padding frames
 #+/-zero-frame-eoc-marker the implementation versions for the moment
 device-initialize-content-header : factored out from the writing
  process to be available for the publish command.
 device-write-content : initialize the basic's header properties, but do not write.

frame.lisp :
 unget-read-frame : added for use in device read to push back non-body frames
  and rheat them as an eof indicator.

utilities.lisp :
 undequeue : for unget-read-frame
  • Loading branch information
lisp committed Jul 12, 2011
1 parent aa0cd0d commit d772d24
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 63 deletions.
4 changes: 3 additions & 1 deletion amqp-device.lisp
Expand Up @@ -364,7 +364,9 @@
(let ((i start) (let ((i start)
(start-buffpos buffpos) (start-buffpos buffpos)
(char #\null)) (char #\null))
(loop (unless (setf char (funcall decoder #'buffer-extract-byte device)) (loop (when (>= i end)
(return (values (- i start) nil)))
(unless (setf char (funcall decoder #'buffer-extract-byte device))
(return (values (- i start) :eof))) (return (values (- i start) :eof)))
(setf last-char-read-size (- buffpos start-buffpos)) (setf last-char-read-size (- buffpos start-buffpos))
(setf start-buffpos buffpos) (setf start-buffpos buffpos)
Expand Down
2 changes: 1 addition & 1 deletion classes.lisp
Expand Up @@ -706,7 +706,7 @@
;; try to determine the size ;; try to determine the size
(setf body-size (channel-compute-body-size channel body content-type)) (setf body-size (channel-compute-body-size channel body content-type))
(etypecase body-size (etypecase body-size
(null (null
(setf (getf headers :transfer-encoding) "chunked") (setf (getf headers :transfer-encoding) "chunked")
(setf body-size (device-buffer-length channel))) (setf body-size (device-buffer-length channel)))
(integer (integer
Expand Down
33 changes: 11 additions & 22 deletions commands.lisp
Expand Up @@ -446,7 +446,8 @@ messages in between sending the cancel method and receiving the cancel-ok reply.
(let ((channel (object-channel basic))) (let ((channel (object-channel basic)))
;; save the tag for eventual acknowledgment - either by app or below ;; save the tag for eventual acknowledgment - either by app or below
(setf (amqp:basic-delivery-tag basic) delivery-tag) (setf (amqp:basic-delivery-tag basic) delivery-tag)
(prog1 (apply #'device-read-content channel args) (multiple-value-prog1 (values (apply #'device-read-content channel args)
(amqp:basic-headers basic))
(when (and (channel-acknowledge-messages channel) (when (and (channel-acknowledge-messages channel)
;; in case the ack was managed elsewhere, test ;; in case the ack was managed elsewhere, test
(eql (amqp:basic-delivery-tag basic) delivery-tag)) (eql (amqp:basic-delivery-tag basic) delivery-tag))
Expand Down Expand Up @@ -530,7 +531,8 @@ messages in between sending the cancel method and receiving the cancel-ok reply.
(amqp:log :debug basic "respond-to-get, get-ok: ~s" get-ok-args) (amqp:log :debug basic "respond-to-get, get-ok: ~s" get-ok-args)
(let ((channel (object-channel basic))) (let ((channel (object-channel basic)))
(return-from command-case (return-from command-case
(prog1 (apply #'device-read-content channel :body body get-ok-args) (multiple-value-prog1 (values (apply #'device-read-content channel :body body get-ok-args)
(amqp:basic-headers basic))
(unless (amqp:basic-no-ack basic) (unless (amqp:basic-no-ack basic)
(amqp::send-ack basic :delivery-tag delivery-tag)))))))))) (amqp::send-ack basic :delivery-tag delivery-tag))))))))))


Expand All @@ -543,7 +545,7 @@ messages in between sending the cancel method and receiving the cancel-ok reply.
(declare (dynamic-extent args)) (declare (dynamic-extent args))
(let ((channel (object-channel basic))) (let ((channel (object-channel basic)))
;;; nb. do not ack a get-ok ;;; nb. do not ack a get-ok
(prog1 (apply #'device-read-content channel args)))))) (apply #'device-read-content channel args)))))




(def-amqp-command amqp:Get-Empty (class &key) (def-amqp-command amqp:Get-Empty (class &key)
Expand Down Expand Up @@ -616,28 +618,15 @@ any, is committed.")
(apply #'amqp::request-publish (amqp:channel.basic channel) args)) (apply #'amqp::request-publish (amqp:channel.basic channel) args))


(:method ((basic amqp:basic) &rest args &key (body nil body-s) (:method ((basic amqp:basic) &rest args &key (body nil body-s)
(ticket nil t-s) (exchange nil e-s)
(exchange (amqp:basic-exchange basic)) &allow-other-keys)
(routing-key (amqp:basic-routing-key basic)) (when e-s
(mandatory (amqp:basic-mandatory basic)) (setf exchange (amqp:exchange-exchange exchange)) ; coerce to a string
(immediate (amqp:basic-immediate basic)) (setf (amqp:basic-exchange basic) exchange)) ; cache for possible use in chunk headers
content-type content-encoding headers delivery-mode
priority correlation-id reply-to expiration message-id timestamp
type user-id)
(declare (ignore content-type content-encoding headers delivery-mode
priority correlation-id reply-to expiration message-id timestamp
type user-id))
(setf exchange (amqp:exchange-exchange exchange)) ; coerce to a string
(setf (amqp:basic-exchange basic) exchange) ; cache for possible use in chunk headers
(when body-s (when body-s
(setf args (copy-list args)) (setf args (copy-list args))
(remf args :body)) (remf args :body))
(if t-s ; version variation (apply #'shared-initialize basic t args)
(amqp::send-publish basic :ticket ticket :exchange exchange :routing-key routing-key
:mandatory mandatory :immediate immediate)
(amqp::send-publish basic :exchange exchange :routing-key routing-key
:mandatory mandatory :immediate immediate))

(let ((channel (object-channel basic))) (let ((channel (object-channel basic)))
(apply #'device-write-content channel body :exchange exchange args))))) (apply #'device-write-content channel body :exchange exchange args)))))


Expand Down

0 comments on commit d772d24

Please sign in to comment.