amqp091
Generated by tinox doc
tinox.core.amqp091, split out of the bundled stdlib as a standalone tinox-central package.
Publish consume
import tinox.core.amqp091
import tinox.core.encoding
class Main
{
fnc main() -> Int32
{
const connection: AmqpConnection091 = AmqpConnection091::connect("localhost", 5672, "/", "guest", "guest")
const amqpChannel: AmqpChannel091 = AmqpChannel091::open(connection)
const queue: String = amqpChannel.declareQueue("jobs", true, false, false)
const body: List<Int64> = Encoding::toUtf8("hello")
amqpChannel.publish("", queue, body, "text/plain")
amqpChannel.consume(queue)
const msg: AmqpMessage091 = amqpChannel.nextMessage()
println(msg.body.len().toString() + " bytes received")
amqpChannel.ack(msg.deliveryTag)
connection.close()
return 0
}
}
class Amqp091
Methods
fn dial(host: String, port: Int64) → Int64
fn dialTls(host: String, port: Int64, verify: Bool) → Int64
fn sendProtocolHeader(conn: Int64) → Nothing
fn checkHandshakeResponse(conn: Int64) → Bool
fn readFrame(conn: Int64) → AmqpFrame091
fn writeFrame(conn: Int64, frameType: Int64, chanId: Int64, payload: List<Int64>) → Nothing
fn encodeMethodPayload(classId: Int64, methodId: Int64, args: List<Int64>) → List<Int64>
fn decodeMethodPayload(payload: List<Int64>) → AmqpMethodFrame091
fn saslPlainResponse(user: String, pass: String) → List<Int64>
fn describeAndAckClose(conn: Int64, chanId: Int64, mf: AmqpMethodFrame091, closeOkMethodId: Int64) → String
class AmqpChannel091
Fields
conn | Int64 | |
chanId | Int64 | |
frameMax | Int64 | |
errorMessage | String | |
confirmsEnabled | Bool | |
lastDeliveryTag | Int64 | |
inbox | Channel<AmqpFrame091> | |
Methods
fn open(connection: AmqpConnection091) → AmqpChannel091
fn declareQueue(name: String, durable: Bool, exclusive: Bool, autoDelete: Bool) → String
fn declareExchange(name: String, exchangeType: String, durable: Bool, autoDelete: Bool) → Bool
fn bindQueue(queue: String, exchange: String, routingKey: String) → Bool
fn qos(prefetchCount: Int64) → Bool
fn confirmSelect() → Bool
fn publish(exchange: String, routingKey: String, body: List<Int64>, contentType: String) → Int64
fn consume(queue: String) → String
fn nextMessage() → AmqpMessage091
fn reject(deliveryTag: Int64, requeue: Bool) → Nothing
fn ack(deliveryTag: Int64) → Nothing
fn waitForConfirm() → AmqpConfirmResult091
class AmqpConfirmResult091
Fields
deliveryTag | Int64 | |
multiple | Bool | |
ack | Bool | |
ok | Bool | |
errorMessage | String | |
class AmqpConnection091
Fields
conn | Int64 | |
frameMax | Int64 | |
channelMax | Int64 | |
heartbeat | Int64 | |
errorMessage | String | |
heartbeatRunning | Bool | |
heartbeatHandle | Int64 | |
channelIds | List<Int64> | |
channelInboxes | List<Channel<AmqpFrame091>> | |
connectionInbox | Channel<AmqpFrame091> | |
dispatcherRunning | Bool | |
dispatcherHandle | Int64 | |
nextChanId | Int64 | |
Methods
fn connect(host: String, port: Int64, vhost: String, user: String, pass: String) → AmqpConnection091
fn connectTls(host: String, port: Int64, vhost: String, user: String, pass: String, verify: Bool) → AmqpConnection091
fn finishHandshake(conn: Int64, vhost: String, user: String, pass: String) → AmqpConnection091
fn allocateChanId() → Int64
fn registerChannelInbox(chanId: Int64, inbox: Channel<AmqpFrame091>) → Nothing
fn sendHeartbeat() → Nothing
fn startHeartbeat(intervalMs: Int64) → Nothing
fn stopHeartbeat() → Nothing
fn close() → Nothing
fnc amqp091DispatchLoop(connection: AmqpConnection091) → Int64
fnc amqp091HeartbeatLoop(conn: AmqpConnection091, intervalMs: Int64) → Int64
class AmqpFrame091
Fields
frameType | Int64 | |
chanId | Int64 | |
payload | List<Int64> | |
class AmqpMessage091
Fields
deliveryTag | Int64 | |
exchange | String | |
routingKey | String | |
contentType | String | |
body | List<Int64> | |
ok | Bool | |
errorMessage | String | |
redelivered | Bool | True if the broker marks this delivery as redelivered (an earlier delivery was not acknowledged) |
messageId | String | The message-id property, "" if the publisher set none; the natural idempotency key |
class AmqpMethodFrame091
Fields
classId | Int64 | |
methodId | Int64 | |
args | List<Int64> | |
fn tinoxBytesToString(bytes: List<Int64>) → String
class AmqpReader091
Fields
bytes | List<Int64> | |
pos | Int64 | |
truncated | Bool | |
Methods
fn new(bytes: List<Int64>) → AmqpReader091
fn remaining() → Int64
fn octet() → Int64
fn short() → Int64
fn long() → Int64
fn longSigned() → Int64
fn longlong() → Int64
fn rawStr(n: Int64) → String
fn shortstr() → String
fn longstr() → String
fn fieldValue() → AmqpFieldValue091
fn fieldTable() → Map<String, AmqpFieldValue091>
fn fieldArray() → List<AmqpFieldValue091>
class AmqpWriter091
Fields
bytes | List<Int64> | |
tooLong | Bool | |
Methods
fn new() → AmqpWriter091
fn hasError() → Bool
fn octet(v: Int64) → Nothing
fn short(v: Int64) → Nothing
fn long(v: Int64) → Nothing
fn longlong(v: Int64) → Nothing
fn rawStr(s: String) → Nothing
fn rawBytes(data: List<Int64>) → Nothing
fn shortstr(s: String) → Nothing
fn longstr(s: String) → Nothing
fn longstrBytes(data: List<Int64>) → Nothing
fn fieldValue(v: AmqpFieldValue091) → Nothing
fn fieldTable(t: Map<String, AmqpFieldValue091>) → Nothing
fn fieldArray(a: List<AmqpFieldValue091>) → Nothing
class IdempotencyWindow091
* A bounded, in-memory window of recently handled idempotency keys (typically
* AmqpMessage091.messageId). It suppresses redeliveries within one process -- not across
* restarts or instances; durable de-duplication needs a database unique key. The window keeps
* at most `capacity` keys (the oldest are forgotten first), so it cannot grow without bound.
*
* if (!this.window.firstSeen(msg.messageId)) { return } // duplicate: acknowledged, not handled
* ... handle ...
* (on failure the handler throws and the key is forgotten by the caller via forget())
Fields
capacity | Int64 | |
seen | Map<String, Bool> | |
order | List<String> | |
Methods
fnc create(capacity: Int64) → IdempotencyWindow091
fn firstSeen(key: String) → Bool
True the first time a key is offered (and records it); false for a duplicate. An empty key is never a duplicate.
fn forget(key: String) → Nothing
Removes a key, e.g. after a failed attempt so that the retry is not mistaken for a duplicate
class MessageFailure091
* Failure policy of an @Amqp091Consumer handler, used by the generated receive loop
* (@MessageFailure(maxAttempts, backoffMs[, "dead-letter-queue"]) on the @OnMessage method).
*
* A delivery is acknowledged only when the handler returned normally. After a failure the
* handler runs again in the same process, waiting backoffMs * 2^(attempt-1) (capped at 60 s)
* in between, until maxAttempts have failed. Then the message is settled, never acknowledged
* as if handled:
* - with a dead-letter queue: it is published there (default exchange, routing key = the
* queue name; the body and content type are kept, headers are not) and only then
* acknowledged; if that publish cannot be done the delivery is rejected with requeue, so
* the message stays in the broker instead of being lost;
* - without one: basic.reject(requeue=false) -- the broker discards it or dead-letters it
* through the queue's own x-dead-letter-exchange. Broker semantics are not replaced.
* Retries are in-process: a crash or restart leaves the delivery unacknowledged and the broker
* redelivers it (redelivered == true) -- at-least-once, never exactly-once. Handlers must be
* idempotent; IdempotencyWindow091 helps for the redelivery window.
Methods
fnc onFailure(chan: AmqpChannel091, msg: AmqpMessage091, attempt: Int64, maxAttempts: Int64, backoffMs: Int64, deadLetterQueue: String) → Int64
* Called after a failed attempt (1-based). Returns 0 when the handler should run again (the
* backoff already elapsed), 1 when the message has been settled.