/** * Mock implementation of a message exchange for testing purposes. * Exchanges route messages to queues based on routing keys and exchange type. * * @example * ```typescript * const exchange = new Exchange({ name: 'user-events', type: 'topic' }); * * // Publish a message * await exchange.publish( * { userId: 123, action: 'created' }, * { routingKey: 'user.created' } * ); * * // Check published messages * console.log(exchange.publishedMessages); * ``` */ declare class Exchange { /** The name of the exchange */ readonly name: string; /** The type of exchange routing (topic, direct, or fanout) */ readonly type: 'topic' | 'direct' | 'fanout'; /** Whether publisher confirmations are enabled */ readonly confirm: boolean; /** Array of all messages published to this exchange */ publishedMessages: Array<{ message: object; [key: string]: any; }>; /** Array of messages scheduled for delayed publishing */ delayedMessages: Array<{ message: object; [key: string]: any; }>; /** * Creates a new Exchange instance with the specified configuration * * @param {ExchangeParams} params - Exchange configuration parameters * @param {string} params.name - The name of the exchange * @param {'topic' | 'direct' | 'fanout'} params.type - The exchange type * @param {boolean} [params.confirm=true] - Whether to enable publisher confirmations * * @example * ```typescript * const topicExchange = new Exchange({ * name: 'events', * type: 'topic', * confirm: true * }); * ``` */ constructor(params: ExchangeParams); /** * Publishes a message to the exchange with the specified properties. * The message and properties are stored in publishedMessages for testing verification. * * @param {object} message - The message payload to publish * @param {object} properties - Message properties including routing key * @param {string} properties.routingKey - The routing key for message routing * @returns {Promise} Promise that resolves when message is published * * @example * ```typescript * await exchange.publish( * { orderId: 456, status: 'completed' }, * { routingKey: 'order.completed', contentType: 'application/json' } * ); * ``` */ publish(message: object, properties: object): Promise; /** * Publishes a message to the exchange after a specified delay. * Useful for testing delayed message scenarios. * * @param {object} message - The message payload to publish * @param {object} properties - Message properties including delay and routing key * @param {number} properties.delay - Delay in milliseconds before publishing * @param {string} properties.routingKey - The routing key for message routing * @returns {Promise} Promise that resolves immediately (message publishes after delay) * @throws {Error} If delay property is not provided * * @example * ```typescript * // Publish message after 5 seconds * await exchange.delayedPublish( * { reminder: 'Payment due' }, * { delay: 5000, routingKey: 'reminder.payment' } * ); * ``` */ delayedPublish(message: object, properties: object): Promise; /** * Clears the history of published messages and delayed messages. * Useful for resetting state between tests. * * @example * ```typescript * exchange.clearHistory(); * console.log(exchange.publishedMessages.length); // 0 * console.log(exchange.delayedMessages.length); // 0 * ``` */ clearHistory(): void; } export default Exchange;