import * as Amqp from "./amqp" ; import { Client } from "./client" ; import { UnimplementedError } from "./errors" ; import { MessageBroker } from "./message_broker" ; import { NullBackend } from "./null_backend" ; import * as Redis from "./redis" ; import { ResultBackend } from "./result_backend" ; import { getScheme , Scheme } from "./uri" ; import { isNullOrUndefined } from "./utility" ; import * as Uuid from "uuid" ; param brokerUrl param resultBackend returns throws see createBackend see createBroker export const createClient = ( { brokerUrl , resultBackend } ) : Client => { const id = Uuid . v4 ( ) ; const backend = ( ( ) => { if ( isNullOrUndefined ( resultBackend ) ) { return new NullBackend ( ) ; } return createBackend ( id , resultBackend ) ; } ) ( ) ; const brokers = ( ( ) => { if ( typeof brokerUrl === "string" ) { return [ createBroker ( brokerUrl ) ] ; } return brokerUrl . map ( createBroker ) ; } ) ( ) ; return new Client ( { backend , brokers , id , } ) ; } ; param id param rawUri returns throws throws export const createBackend = ( id , rawUri ) : ResultBackend => { try { const scheme = getScheme ( rawUri ) ; switch ( scheme ) { case Scheme . Redis : return new Redis . RedisBackend ( new Redis . RedisTcpOptions ( Redis . parseTcpUri ( rawUri ) ) ) ; case Scheme . RedisSocket : return new Redis . RedisBackend ( new Redis . RedisSocketOptions ( Redis . parseSocketUri ( rawUri ) ) ) ; case Scheme . RedisSentinel : return new Redis . RedisBackend ( new Redis . RedisSentinelOptions ( Redis . parseSentinelUri ( rawUri ) ) ) ; case Scheme . Rpc : return new Amqp . RpcBackend ( id , Amqp . parseAmqpUri ( rawUri ) ) ; } } catch ( error ) { throw new Error ( "Celery.Factories.createBackend: could not parse URI " + `${ rawUri }: ${ error }` ) ; } throw new UnimplementedError ( "Celery.Factory.createBackend" ) ; } ; param rawUri returns throws throws export const createBroker = ( rawUri ) : MessageBroker => { try { const scheme = getScheme ( rawUri ) ; switch ( scheme ) { case Scheme . Redis : return new Redis . RedisBroker ( new Redis . RedisTcpOptions ( Redis . parseTcpUri ( rawUri ) ) ) ; case Scheme . RedisSocket : return new Redis . RedisBroker ( new Redis . RedisSocketOptions ( Redis . parseSocketUri ( rawUri ) ) ) ; case Scheme . RedisSentinel : return new Redis . RedisBroker ( new Redis . RedisSentinelOptions ( Redis . parseSentinelUri ( rawUri ) ) ) ; case Scheme . Amqp : return new Amqp . AmqpBroker ( Amqp . parseAmqpUri ( rawUri ) ) ; } } catch ( error ) { throw new Error ( "Celery.Factories.createBroker: could not parse URI " + `${ rawUri }: ${ error }` ) ; } throw new UnimplementedError ( "Celery.Factory.createBroker" ) ; } ;