src/transporters/index.js
function resolve(opt) {
	if (opt instanceof Transporters.Base) {
		return opt;
	} else if (_.isString(opt)) {
		let TransporterClass = getByName(opt);
		if (TransporterClass)
			return new TransporterClass();

		if (opt.startsWith("nats://"))
			TransporterClass = Transporters.NATS;
		else if (opt.startsWith("mqtt://") || opt.startsWith("mqtts://"))
			TransporterClass = Transporters.MQTT;
		else if (opt.startsWith("redis://") || opt.startsWith("rediss://"))
			TransporterClass = Transporters.Redis;
		else if (opt.startsWith("amqp://") || opt.startsWith("amqps://"))
			TransporterClass = Transporters.AMQP;
		else if (opt.startsWith("kafka://"))
			TransporterClass = Transporters.Kafka;
		else if (opt.startsWith("stan://"))
			TransporterClass = Transporters.STAN;
		else if (opt.startsWith("tcp://"))
			TransporterClass = Transporters.TCP;

		if (TransporterClass)
			return new TransporterClass(opt);
		else
			throw new BrokerOptionsError(`Invalid transporter type '${opt}'.`, { type: opt });

	} else if (_.isObject(opt)) {
		let TransporterClass = getByName(opt.type || "NATS");

		if (TransporterClass)
			return new TransporterClass(opt.options);
		else
			throw new BrokerOptionsError(`Invalid transporter type '${opt.type}'.`, { type: opt.type });
	}

	return null;
}
function resolve(opt) {
	if (opt instanceof Transporters.Base) {
		return opt;
	} else if (_.isString(opt)) {
		let TransporterClass = getByName(opt);
		if (TransporterClass)
			return new TransporterClass();

		if (opt.startsWith("nats://"))
			TransporterClass = Transporters.NATS;
		else if (opt.startsWith("mqtt://") || opt.startsWith("mqtts://"))
			TransporterClass = Transporters.MQTT;
		else if (opt.startsWith("redis://") || opt.startsWith("rediss://"))
			TransporterClass = Transporters.Redis;
		else if (opt.startsWith("amqp://") || opt.startsWith("amqps://"))
			TransporterClass = Transporters.AMQP;
		else if (opt.startsWith("kafka://"))
			TransporterClass = Transporters.Kafka;
		else if (opt.startsWith("stan://"))
			TransporterClass = Transporters.STAN;
		else if (opt.startsWith("tcp://"))
			TransporterClass = Transporters.TCP;

		if (TransporterClass)
			return new TransporterClass(opt);
		else
			throw new BrokerOptionsError(`Invalid transporter type '${opt}'.`, { type: opt });

	} else if (_.isObject(opt)) {
		let TransporterClass = getByName(opt.type || "NATS");

		if (TransporterClass)
			return new TransporterClass(opt.options);
		else
			throw new BrokerOptionsError(`Invalid transporter type '${opt.type}'.`, { type: opt.type });
	}

	return null;
}
function resolve ( opt ) { if ( opt instanceof Transporters . Base ) { return opt ; } else if ( _ . isString ( opt ) ) { let TransporterClass = getByName ( opt ) ; if ( TransporterClass ) return new TransporterClass ( ) ; if ( opt . startsWith ( "nats://" ) ) TransporterClass = Transporters . NATS ; else if ( opt . startsWith ( "mqtt://" ) || opt . startsWith ( "mqtts://" ) ) TransporterClass = Transporters . MQTT ; else if ( opt . startsWith ( "redis://" ) || opt . startsWith ( "rediss://" ) ) TransporterClass = Transporters . Redis ; else if ( opt . startsWith ( "amqp://" ) || opt . startsWith ( "amqps://" ) ) TransporterClass = Transporters . AMQP ; else if ( opt . startsWith ( "kafka://" ) ) TransporterClass = Transporters . Kafka ; else if ( opt . startsWith ( "stan://" ) ) TransporterClass = Transporters . STAN ; else if ( opt . startsWith ( "tcp://" ) ) TransporterClass = Transporters . TCP ; if ( TransporterClass ) return new TransporterClass ( opt ) ; else throw new BrokerOptionsError ( ` ${ opt } ` , { type : opt } ) ; } else if ( _ . isObject ( opt ) ) { let TransporterClass = getByName ( opt . type || "NATS" ) ; if ( TransporterClass ) return new TransporterClass ( opt . options ) ; else throw new BrokerOptionsError ( ` ${ opt . type } ` , { type : opt . type } ) ; } return null ; }
Resolve transporter by name

@param {object|string} opt
@returns {Transporter}
Resolve transporter by name