Skip to content

Commit

Permalink
Fix kafka header with null values
Browse files Browse the repository at this point in the history
- Caused by NullPointerException
  • Loading branch information
Harry committed Jul 5, 2022
1 parent 4786a06 commit ac20cf2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ziggurat/messaging/producer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

(defn- record-headers->map [record-headers]
(reduce (fn [header-map record-header]
(assoc header-map (.key record-header) (String. (.value record-header))))
(assoc header-map (.key record-header) (String. (or (.value record-header) ""))))
{}
record-headers))

Expand Down
5 changes: 3 additions & 2 deletions test/ziggurat/messaging/producer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@
(testing "publish to delay queue publishes with parsed record headers"
(fix/with-queues
{:default {:handler-fn #(constantly nil)}}
(let [test-message-payload (assoc message-payload :headers (RecordHeaders. (list (RecordHeader. "key" (byte-array (map byte "value"))))))
(let [test-message-payload (assoc message-payload :headers (RecordHeaders. (list (RecordHeader. "key" (byte-array (map byte "value")))
(RecordHeader. "nil" nil))))
expected-props {:content-type "application/octet-stream"
:persistent true
:expiration (str (get-in (rabbitmq-config) [:delay :queue-timeout-ms]))
:headers {"key" "value"}}]
:headers {"key" "value" "nil" ""}}]
(with-redefs [lb/publish (fn [_ _ _ _ props]
(is (= expected-props props)))
metrics/multi-ns-report-histogram (fn [_ _ _] nil)]
Expand Down

0 comments on commit ac20cf2

Please sign in to comment.