Skip to content

Commit

Permalink
Merge 7855a03 into 6756166
Browse files Browse the repository at this point in the history
  • Loading branch information
dwickr committed Apr 26, 2024
2 parents 6756166 + 7855a03 commit a0ca43d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Options is a hash that can contain the following:
| **pass** | the password for the specified user. | `"guest"` |
| **timeout** | how long to wait for a connection to be established in milliseconds. | `2000` |
| **heartbeat** | how often the client and server check to see if they can still reacheach other, specified in seconds. | `30` |
| **frameMax** | the size in bytes of the maximum frame allowed over the connection. | `4096` |
| **replyQueue** | the name of the reply queue to use. | unique to the process |
| **publishTimeout** | the default timeout in milliseconds for a publish call. | |
| **replyTimeout** | the default timeout in milliseconds to wait for a reply. | |
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/connection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Connection', function () {
});

it('should assign uri to connection', function () {
connected.uri.should.equal('amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=30');
connected.uri.should.equal('amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=30&frameMax=4096');
});

after(function () {
Expand All @@ -29,11 +29,11 @@ describe('Connection', function () {
connected = c;
done();
});
rabbit.addConnection({ name: 'connectionWithUri', uri: 'amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=11' });
rabbit.addConnection({ name: 'connectionWithUri', uri: 'amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=11&frameMax=8192' });
});

it('should assign uri to connection', function () {
connected.uri.should.equal('amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=11');
connected.uri.should.equal('amqp://guest:guest@127.0.0.1:5672/%2f?heartbeat=11&frameMax=8192');
});

after(function () {
Expand Down
11 changes: 7 additions & 4 deletions src/amqp/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function getOption (opts, key, alt) {
}
}

function getUri (protocol, user, pass, server, port, vhost, heartbeat) {
return `${protocol}://${user}:${pass}@${server}:${port}/${vhost}?heartbeat=${heartbeat}`;
function getUri (protocol, user, pass, server, port, vhost, heartbeat, frameMax) {
return `${protocol}://${user}:${pass}@${server}:${port}/${vhost}?heartbeat=${heartbeat}&frameMax=${frameMax}`;
}

function max (x, y) {
Expand All @@ -59,14 +59,16 @@ function parseUri (uri) {
if (uri) {
const parsed = new url.URL(uri);
const heartbeat = parsed.searchParams.get('heartbeat');
const frameMax = parsed.searchParams.get('frameMax');
return {
useSSL: parsed.protocol.startsWith('amqps'),
user: decodeURIComponent(parsed.username),
pass: decodeURIComponent(parsed.password),
host: parsed.hostname,
port: parsed.port,
vhost: parsed.pathname ? parsed.pathname.slice(1) : undefined,
heartbeat: heartbeat
heartbeat: heartbeat,
frameMax: frameMax
};
}
}
Expand Down Expand Up @@ -108,6 +110,7 @@ const Adapter = function (parameters) {
this.pass = getOption(parameters, 'RABBIT_PASSWORD') || getOption(parameters, 'pass', 'guest');
this.user = getOption(parameters, 'RABBIT_USER') || getOption(parameters, 'user', 'guest');
this.vhost = getOption(parameters, 'RABBIT_VHOST') || getOption(parameters, 'vhost', '%2f');
this.frameMax = getOption(parameters, 'RABBIT_FRAME_MAX') || getOption(parameters, 'frameMax', 4096);
const timeout = getOption(parameters, 'RABBIT_TIMEOUT') || getOption(parameters, 'timeout', 2000);
const certPath = getOption(parameters, 'RABBIT_CERT') || getOption(parameters, 'certPath');
const keyPath = getOption(parameters, 'RABBIT_KEY') || getOption(parameters, 'keyPath');
Expand Down Expand Up @@ -193,7 +196,7 @@ Adapter.prototype.bumpIndex = function () {
Adapter.prototype.getNextUri = function () {
const server = this.getNext(this.servers);
const port = this.getNext(this.ports);
const uri = getUri(this.protocol, encodeURIComponent(this.user), encodeURIComponent(this.pass), server, port, this.vhost, this.heartbeat);
const uri = getUri(this.protocol, encodeURIComponent(this.user), encodeURIComponent(this.pass), server, port, this.vhost, this.heartbeat, this.frameMax);
return [uri, server];
};

Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ declare namespace Broker {
pass?: string;
timeout?: number;
heartbeat?: number;
frameMax?: number;
replyQueue?:
| boolean
| string
Expand Down

0 comments on commit a0ca43d

Please sign in to comment.