carotte/publisher
Types
pub opaque type HeaderList
pub type HeaderValue {
BoolHeader(Bool)
FloatHeader(Float)
IntHeader(Int)
StringHeader(String)
ListHeader(List(HeaderValue))
}
Constructors
-
BoolHeader(Bool) -
FloatHeader(Float) -
IntHeader(Int) -
StringHeader(String) -
ListHeader(List(HeaderValue))
pub type PublishOption {
Mandatory(Bool)
ContentType(String)
ContentEncoding(String)
Headers(HeaderList)
Persistent(Bool)
CorrelationId(String)
Priority(Int)
ReplyTo(String)
Expiration(String)
MessageId(String)
Timestamp(Int)
Type(String)
UserId(String)
AppId(String)
}
Constructors
-
Mandatory(Bool)If set, returns an error if the broker can’t route the message to a queue
-
ContentType(String)MIME Content type
-
ContentEncoding(String)MIME Content encoding
-
Headers(HeaderList)Headers to attach to the message. Use
headers_from_listto create headers for sending, andheaders_to_listto read headers from received messages. -
Persistent(Bool)If set, uses persistent delivery mode. Messages marked as persistent that are delivered to durable queues will be logged to disk
-
CorrelationId(String)Arbitrary application-specific message identifier
-
Priority(Int)Message priority, ranging from 0 to 9
-
ReplyTo(String)Name of the reply queue
-
Expiration(String)How long the message is valid (in milliseconds)
-
MessageId(String)Message identifier
-
Timestamp(Int)timestamp associated with this message (epoch time)
-
Type(String)Message type
-
UserId(String)Creating user ID. RabbitMQ will validate this against the active connection user
-
AppId(String)Application ID
Values
pub fn empty_headers() -> HeaderList
Create an empty HeaderList. Useful for pattern matching or when no headers are needed.
pub fn headers_from_list(
list: List(#(String, HeaderValue)),
) -> HeaderList
Create a HeaderList from a list of name-value pairs. Use this to construct headers for messages.
Example
let headers = headers_from_list([
#("user_id", StringHeader("123")),
#("retry_count", IntHeader(3)),
#("is_test", BoolHeader(True)),
])
pub fn headers_to_list(
headers: HeaderList,
) -> List(#(String, HeaderValue))
Convert a HeaderList back to a list of name-value pairs. Use this to read headers from received messages.
Example
case queue.subscribe(channel, "my_queue", fn(payload, _deliver) {
let headers = publisher.headers_to_list(payload.headers)
// headers: List(#(String, HeaderValue))
})
pub fn publish(
channel channel: channel.Channel,
exchange exchange: String,
routing_key routing_key: String,
payload payload: String,
options options: List(PublishOption),
) -> Result(Nil, carotte.CarotteError)
Publish a message ‘payload’ to an exchange
The routing_key is used to filter messages from the exchange
The options are used to set message properties