@amqp-contract/client
v0.25.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"],
})
)._unsafeUnwrap();
// Publish message with explicit error handling
const result = await client.publish("orderCreated", {
orderId: "ORD-123",
amount: 99.99,
});
result.match(
() => console.log("Published successfully"),
(error) => console.error("Publish failed:", error),
);
// Clean up
await client.close();Error Handling
The client uses Result types from neverthrow 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
