Open jupiter opened 9 years ago
I've implemented a simple parser just for that, here:
https://github.com/disintegrator/seneca-amqp-transport/blob/develop/lib/amqp-uri.js
No redis://
protocol support, tough.
@nfantone This creates an URL, right? I think it will be trivial to parse an AMQP and Redis URL using core URL, e.g. require('url')
.
@jupiter
This creates an URL, right?
It does. Converts an object like:
{
hostname: 'dev.rabbitmq.com',
port: 5672,
vhost: 'seneca',
username: 'guest',
password: 'guest',
frameMax: 1024
}
to an URI like amqp://guest:guest@dev.rabbitmq.com:5672/seneca?frameMax=1024
.
I think it will be trivial to parse an AMQP and Redis URL
You mean you actually need the other way around: turn an URI into an object. Yes, it is as trivial as:
var url = require('url');
url.parse('amqp://guest:guest@dev.rabbitmq.com:5672/seneca?frameMax=1024')
Url {
protocol: 'amqp:',
slashes: true,
auth: 'guest:guest',
host: 'dev.rabbitmq.com:5672',
port: '5672',
hostname: 'dev.rabbitmq.com',
hash: null,
search: '?frameMax=1024',
query: 'frameMax=1024',
pathname: '/seneca',
path: '/seneca?frameMax=1024',
href: 'amqp://guest:guest@dev.rabbitmq.com:5672/seneca?frameMax=1024' }
It's not exactly the same thing, though. Query string remains a string, for instance. And you don't have support for username
, password
and such.
In our IBM Bluemix investigation, we found that they prefer to use URLs for configuration. We should implement an optional setting of MSB_BROKER_URL, which would define the adapter, host, port, username and password.
For AMQP as per https://www.rabbitmq.com/uri-spec.html and for Redis, something like redis://[:password@]host[:port][/db-number].