llama.core

Core utilities for working with Camel endpoints, messages, exchanges, etc.

body

(body msg)(body msg clazz)

Get the body of the msg, a Message.

See in and out for getting the Message out of an Exchange.

Type conversions. If clazz is provided use a type converter to cast it to clazz. Throws NoTypeConversionAvailableException if conversion fails because the type converter isn’t in the registry. Throws TypeConversionException if the conversion itself fails.

Uses the context of the exchange of msg. If msg has no exchange and context then the DefaultCamelcontext is used.

;; read from a direct exchange, get the in part of the exchange,
;; get the body, serialize to json using Cheshire, get :foo from the dict 
;; and print
(route (from "direct:hello")                   
       (process                                  
         (fn [x] (->> (in x)                   
                      body
                      cheshire.core/parse-string 
                      :foo                       
                      println))))                

exchange

(exchange on)(exchange on in)(exchange on in out)

Create an exchange on context on. Can set in as the In message. If third arg is truthy, set the exchange pattern as InOut. See message and reply.

on can be either a context, another exchange or an endpoint.

(body (in (exchange ctx (message "hi"))))
;; => "hi"

(out-capable? (exchange ctx (message "hi") :out))
;; => true

fail!

(fail! exchange reason)

Fail the exchange because of reason. reason can be a string or exception/throwable.

failed?

(failed? exchange)

Has the exchange failed (its exception is non-nil) or any of its messages faulted? See also fault?.

fault!

(fault! msg)

Fault the message.

fault?

(fault? msg)

Has the message faulted?

headers

(headers msg)

Get the headers of msg as a map.

id

(id msg)

Get the message id of msg.

in

(in x)

With 1 arg, get the body of the In part of an InOut exchange x.

message

(message body & {:keys [id headers], :or {id nil, headers (hash-map)}})

Create a Message, with body String as the body. Optionally with :headers (map) as the headers, and :id as the message id.

out

(out x)

With 1 arg, get the body of the Out part of an InOut exchange x.

out-capable?

(out-capable? x)

If the Exchange in x is an InOut exchange or not.

reply!

(reply! exchange body & {:keys [headers id], :or {headers (hash-map), id nil}})

Reply successfully to an exchange with body. body can be a String message or a Message. If body is string it is converted into to a Message and the optional headers are inserted as the message headers and :id as the message ID. If body is already a Message its headers and id will be unaltered. See message and request-body.

Note. Reply works only on an InOut Exchange. Does nothing if exchange is InOnly.

(route 
   (from "vm:lol")
   (process (fn [x] (reply x "haha")))

(request-body ctx "vm:lol" "hi")
;; => "haha"

request-body

(request-body ctx endpoint body & {:keys [headers], :or {headers {}}})

Synchronously send to endpoint and expect a reply, returns the reply.

Send body (String) to endpoint using the InOut pattern. Optionally send headers in headers.

(route (from "direct:foo")
       (process (fn [x] (reply x "Is it African or European?"))))

;; start the route, add to context, etc.

(request-body ctx "direct:foo" "How much weight can an unladen swallow carry?")
;; => "Is it African or European?"

send-body

(send-body ctx endpoint body & {:keys [headers], :or {headers {}}})

Synchronously send body as message to endpoint.

Sends body (String) to endpoint. Optionally add headers in headers.

set-body!

(set-body! msg body)

Set the body of msg to body.

set-in!

(set-in! xchg m)

Set the In part of an exchange to m.

set-out!

(set-out! xchg m)

Set the Out part of an exchange to m. No-op on InOnly exchanges.