我对 Clojure 完全陌生。有时我仍然在为阅读功能而苦恼。
我正在尝试更改此功能以使用 checkshire。这是我的尝试:
defn- json->messages [json]
(let [records (:amazon.aws.sqs/records (cheshire/decode
json
:key-fn key-reader
:value-fn value-reader))
add-origin-queue (fn [record]
(let [event-source-arn (:amazon.aws.sqs/event-source-arn record)
queue-name (arn->queue-name event-source-arn)]
(assoc record :amazon.aws.sqs/queue-name queue-name)))]
(map add-origin-queue records)))
功能键阅读器功能:
(def ^:private
key-reader
(memoize (fn [key]
(let [kebab-key (if (= "md5OfBody" key)
"md5-of-body"
(csk/->kebab-case key))]
(keyword "amazon.aws.sqs" kebab-key)))))
功能 :
(def ^:private
value-reader
(memoize (fn [key value]
(if (= key :amazon.aws.sqs/receipt-handle)
value-reader
value))))
我比这样调用函数:
(json->messages 消息)
msg 是一个 json 字符串。
但是,我在尝试时收到以下错误:
tech.matterindustries.titan.ion.lambda.sqs-receive/json->messages (sqs_receive.clj:36) 处的执行错误 (ArityException)。传递给的 args (5) 数量错误:cheshire.core/parse-smile