-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
MONOLITH_TRANSPORTER
env var (#29373)
Co-authored-by: Debdut Chakraborty <[email protected]>
- Loading branch information
1 parent
585c49f
commit 3109a76
Showing
4 changed files
with
88 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
feat: *Enterprise* Add support for different transporters to connect multiple monolith instances. | ||
|
||
To use that, you can use the `TRANSPORTER` env var adding "monolith+" to the transporter value. To use NATS for example, your env var should be: | ||
|
||
```bash | ||
export TRANSPORTER="monolith+nats://localhost:4222" | ||
``` |
15 changes: 15 additions & 0 deletions
15
apps/meteor/ee/server/local-services/instance/getTransporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function getTransporter({ transporter, port }: { transporter?: string; port?: string } = {}) { | ||
if (transporter) { | ||
if (!transporter.match(/^(?:monolith\+)/)) { | ||
throw new Error('invalid transporter'); | ||
} | ||
|
||
const [, ...url] = transporter.split('+'); | ||
return url.join(''); | ||
} | ||
|
||
return { | ||
port: port ? port.trim() : 0, | ||
udpDiscovery: false, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...meteor/ee/tests/unit/apps/meteor/ee/server/local-services/instance/getTransporter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { getTransporter } from '../../../../../../../../server/local-services/instance/getTransporter'; | ||
|
||
describe('getTransporter', () => { | ||
it('should return TCP with port 0 by default', () => { | ||
expect(getTransporter()).to.deep.equal({ port: 0, udpDiscovery: false }); | ||
}); | ||
|
||
it('should return TCP with port set via env var', () => { | ||
expect(getTransporter({ port: '1234' })).to.deep.equal({ port: '1234', udpDiscovery: false }); | ||
|
||
expect(getTransporter({ port: ' 1234' })).to.deep.equal({ port: '1234', udpDiscovery: false }); | ||
|
||
expect(getTransporter({ port: ' 1234 ' })).to.deep.equal({ port: '1234', udpDiscovery: false }); | ||
}); | ||
|
||
it('should throw if transporter set incorrectly', () => { | ||
expect(() => getTransporter({ transporter: 'something' })).to.throw('invalid transporter'); | ||
}); | ||
|
||
it('should return transporter if set correctly', () => { | ||
expect(getTransporter({ transporter: 'monolith+nats://address' })).to.equal('nats://address'); | ||
}); | ||
}); |