@amqp-contract/client
v0.10.0
Published
Client utilities for publishing messages using amqp-contract
Maintainers
Readme
@amqp-contract/client
Type-safe AMQP client for publishing messages using amqp-contract with explicit error handling via Result types.
Installation
pnpm add @amqp-contract/clientUsage
import { TypedAmqpClient } from "@amqp-contract/client";
import { contract } from "./contract";
// Create client from contract (automatically connects and waits for connection)
const client = await TypedAmqpClient.create({
contract,
urls: ["amqp://localhost"],
}).resultToPromise();
// Publish message with explicit error handling
const result = await client
.publish("orderCreated", {
orderId: "ORD-123",
amount: 99.99,
})
.resultToPromise();
console.log("Published successfully");
// Clean up
await client.close();Error Handling
The client uses Result types from @swan-io/boxed for explicit error handling. Runtime errors are part of the type signature:
publish(): Result<boolean, TechnicalError | MessageValidationError>Error Types:
TechnicalError- Runtime failures (channel buffer full, network issues, etc.)MessageValidationError- Message fails schema validation
Programming Errors (client not initialized, invalid publisher name) throw exceptions since they indicate bugs caught by TypeScript at compile-time.
API
For complete API documentation, see the Client API Reference.
Documentation
📖 Read the full documentation →
License
MIT
