Kind: Interface
Source: packages/microservices/external/rmq-url.interface.ts
Part of: Microservices
RmqUrl defines the connection components required to build or represent a RabbitMQ broker URL. It captures broker location, authentication, virtual host, and AMQP connection tuning values used by the microservices transport layer.
Properties
| Property | Type |
|---|---|
protocol | string |
hostname | string |
port | number |
username | string |
password | string |
locale | string |
frameMax | number |
heartbeat | number |
vhost | string |
Diagram
mermaidgraph LR RmqUrl["RmqUrl"] RmqUrl --> Protocol["protocol: string"] RmqUrl --> Hostname["hostname: string"] RmqUrl --> Port["port: number"] RmqUrl --> Credentials["username / password"] RmqUrl --> VHost["vhost: string"] RmqUrl --> Locale["locale: string"] RmqUrl --> Tuning["frameMax / heartbeat"] Credentials --> Connection["RabbitMQ Connection"] VHost --> Connection Tuning --> Connection Protocol --> Connection Hostname --> Connection Port --> Connection
Usage
tsimport type { RmqUrl } from './rmq-url.interface';
const rabbitMqConfig: RmqUrl = {
protocol: 'amqp',
hostname: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
locale: 'en_US',
frameMax: 0,
heartbeat: 60,
vhost: '/',
};
const connectionUrl =
`${rabbitMqConfig.protocol}://` +
`${encodeURIComponent(rabbitMqConfig.username)}:` +
`${encodeURIComponent(rabbitMqConfig.password)}@` +
`${rabbitMqConfig.hostname}:${rabbitMqConfig.port}` +
`${rabbitMqConfig.vhost}`;
AI Coding Instructions
- Keep all fields populated when constructing an
RmqUrl; this interface does not mark connection settings as optional. - Use
amqporamqpsforprotocoldepending on whether the RabbitMQ broker requires TLS. - Encode
usernameandpasswordbefore interpolating them into a connection URI, especially when they contain reserved URL characters. - Preserve
vhost,heartbeat, andframeMaxvalues when passing configuration into RabbitMQ transport or connection setup code. - Avoid hardcoding credentials in source files; populate
RmqUrlfrom validated environment or configuration values.
How it works
-
RmqUrlis an exported, public TypeScript interface for the object form of an RMQ connection URL. It declares only optional properties and has no methods or runtime implementation. [packages/microservices/external/rmq-url.interface.ts:4-17] -
Its optional fields are:
protocol,hostname,username,password,locale, andvhostas strings. [packages/microservices/external/rmq-url.interface.ts:8-13,16]port,frameMax, andheartbeatas numbers. [packages/microservices/external/rmq-url.interface.ts:10,14-15]
-
RmqOptions.options.urlsaccepts either an array of URL strings or an array ofRmqUrlobjects; the adjacent documentation says these are connection URLs tried in order. [packages/microservices/interfaces/microservice-configuration.interface.ts:222-228] -
ServerRMQstores this setting asstring[] | RmqUrl[]. Its constructor readsoptions.urlsand falls back to an array containing the RMQ default URL when the setting is falsy. [packages/microservices/server/server-rmq.ts:67,77-85] -
When creating the RMQ client,
ServerRMQpasses the stored URL array directly as the first argument toamqp-connection-manager’sconnectcall. [packages/microservices/server/server-rmq.ts:169-176] -
No validation, normalization, field-level parsing, errors, or side effects are declared by
RmqUrlitself. In the visibleServerRMQpath, individualRmqUrlfields are not inspected before the array is passed toconnect. [packages/microservices/external/rmq-url.interface.ts:7-17] [packages/microservices/server/server-rmq.ts:169-176]
Was this page helpful?