           data (message/get-json-data message)]
       (s/validate p/InventoryRequest data)
       (let [uris (doall (filter (partial get-websocket broker) ((:find-clients broker) (:query data))))
-            response-data {:uris uris}
-            response (-> (message/make-message :message_type "http://puppetlabs.com/inventory_response"
-                                               :targets [(:sender message)]
-                                               :in-reply-to (:id message)
-                                               :sender "pcp:///server")
-                         (message/set-expiry 3 :seconds)
-                         (message/set-json-data response-data))]
+            response-data {:uris uris}]
         (s/validate p/InventoryResponse response-data)
-        (accept-message-for-delivery broker (capsule/wrap response)))))
+        (accept-message-for-delivery
+          broker
+          (-> (message/make-message :message_type "http://puppetlabs.com/inventory_response"
+                                    :targets [(:sender message)]
+                                    :in-reply-to (:id message)
+                                    :sender "pcp:///server")
+              (message/set-json-data response-data)
+              ;; set expiration last so if any of the previous steps take significant time
+              ;; the message doesn't expire
+              (message/set-expiry 3 :seconds)
+              (capsule/wrap))))))
   connection)
 
 (s/defn process-server-message :- Connection

                                           :targets [sender]
                                           :sender "pcp:///server"
                                           :in-reply-to in-reply-to)
                     (message/set-expiry 3 :seconds)
                     (message/set-json-data response_data))]
    response))

(s/defn process-expired-message :- Capsule

  [broker :- Broker message :- Message targets :- [p/Uri]]
  (when (:destination_report message)
    (let [report {:id (:id message)
                  :targets targets}]
      (s/validate p/DestinationReport report)
      (accept-message-for-delivery
        broker
        (-> (message/make-message :targets [(:sender message)]
                                  :message_type "http://puppetlabs.com/destination_report"
                                  :in-reply-to (:id message)
                                  :sender "pcp:///server")
            (message/set-json-data report)
            (message/set-expiry 3 :seconds)
            (capsule/wrap))))))

;; ActiveMQ queue consumers
(s/defn deliver-message
