-
Notifications
You must be signed in to change notification settings - Fork 12
/
amqp_connect.ts
42 lines (36 loc) · 1.03 KB
/
amqp_connect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { AmqpConnection } from "./amqp_connection.ts";
import { AmqpSocket } from "./amqp_socket.ts";
import { AmqpConnectOptions, parseOptions } from "./amqp_connect_options.ts";
export type { AmqpConnectOptions };
export async function connect(): Promise<AmqpConnection>;
export async function connect(
options?: AmqpConnectOptions,
): Promise<AmqpConnection>;
export async function connect(uri?: string): Promise<AmqpConnection>;
export async function connect(
optionsOrUrl?: AmqpConnectOptions | string,
): Promise<AmqpConnection> {
const {
hostname,
port,
username,
password,
heartbeatInterval,
loglevel,
vhost,
frameMax,
tls,
} = parseOptions(optionsOrUrl);
const conn = tls ? await Deno.connectTls({ port, hostname }) : await Deno.connect({ port, hostname });
const socket = new AmqpSocket(conn);
const connection = new AmqpConnection(socket, {
username,
password,
heartbeatInterval,
frameMax,
loglevel,
vhost,
});
await connection.open();
return connection;
}