當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript amqplib.connect函數代碼示例

本文整理匯總了TypeScript中amqplib.connect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect函數的具體用法?TypeScript connect怎麽用?TypeScript connect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了connect函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: to

  to(exchange: string, iO: Observable<any>): Subscription<any> {
    let channel, conn, cachedItems = [];
    let queue = uuid.v4();

    connect(this.config.connString)
    .then(c => conn = c && c.createChannel())
    .then(c => {
      channel = c;

      channel.assertExchange(exchange, 'fanout');
      cachedItems.forEach(item => {
        channel.publish(exchange, '', new Buffer(item));
      });
    })
    .catch(err => { throw err; });

    return iO
      .subscribe(
        msg => {
          if (!channel) {
            return cachedItems.push(msg);
          }

          channel.publish(exchange, '', new Buffer(msg));
        },
        err => console.error(`rabbitSink err, queue: ${queue}`, err),
        () => {
          if (conn) {
            channel.publish(exchange, '', new Buffer('__done'));
            conn.close()
          }
        }
      );
  }
開發者ID:jonesnc,項目名稱:gustav,代碼行數:34,代碼來源:GustavRabbit.ts

示例2: connect

    public connect(
        actionFunction: (message: any, responseCallback: Function) => void
    ): Bluebird.Thenable<Channel> {
        if (!actionFunction) {
            throw new Error('Cannot start RPC_Server without an actionFunction');
        }

        const self: RPC_Server = this;

        return connect(this.uri)
            .then((connection: Connection) => {
                self._connection = connection;
                return connection.createChannel();
            })
            .then((channel: Channel) => {
                self._channel = channel;

                // Assert Queue
                channel.assertQueue(
                    self.queueName,
                    { durable: false }
                );
                channel.prefetch(1);
                if (self.verboseOn) {
                    console.log(`Awaiting RPC Requests On: ${self.queueName}`);
                }

                // Consume Messages
                self.consumeChannel.apply(self, [channel, actionFunction]);

                return self._channel;
            });
    }
開發者ID:db3dev,項目名稱:amqp-rpc-server-controller,代碼行數:33,代碼來源:server.ts

示例3: connect

    public connect(): Observable<Channel> {
        if (!this._uri) {
            return Observable.throw(
                new Error('Uri must be defined in order to start connection')
            );
        }

        const self: RPC_Client = this;

        // Connect to RabbitMQ
        const connPromise: any = connect(this.uri)
            // Assign Connection and Create Channel
            .then((connection: Connection) => {
                self._connection = connection;
                return connection.createChannel();
            })

            // Assign Channel and create consume listener
            .then((channel: Channel) => {
                self._channel = channel;
                channel.setMaxListeners(0);

                // Action to take when message received
                self.consumeChannel.apply(self, [channel]);

                return channel;
            });

        return Observable.fromPromise(connPromise);
    }
開發者ID:db3dev,項目名稱:amqp-rpc-client-controller,代碼行數:30,代碼來源:client.ts

示例4: getChannel

function getChannel(queue: string) {
        return amqplib.connect('amqp://localhost')
        .then(conn => {
            return conn.createChannel();
        })
        .then(channel => {
            channel.assertQueue(queue, {durable: false});
            return channel;
        });
}
開發者ID:gitsearch-io,項目名稱:frontend,代碼行數:10,代碼來源:messageService.ts

示例5: sendSingleMessage

  protected async sendSingleMessage(messageObj, callback: (err, result, disposed?: boolean) => void) {
    const server = await amqp.connect(this.host);
    const channel = await server.createChannel();
    const { sub, pub } = this.getQueues();

    channel.assertQueue(sub, { durable: false });
    channel.assertQueue(pub, { durable: false });

    channel.consume(pub, (message) => this.handleMessage(message, server, callback), { noAck: true });
    channel.sendToQueue(sub, Buffer.from(JSON.stringify(messageObj)));
  }
開發者ID:fanybook,項目名稱:Nestjs30Days,代碼行數:11,代碼來源:rabbitmq.client.ts

示例6: connect

function connect () {

    amqp.connect('amqp://localhost')
        .then((conn)=> conn.createChannel())
        .then((ch)=> {channel = ch; return ch.assertExchange('auth', 'direct')})

        .then(()=>channel.assertQueue('token.auth', {durable: false}))
        .then((q)=>{tokenQueue = q; return channel.bindQueue('token.auth', 'auth', 'token.auth')})

        .then(()=>channel.assertQueue('login.auth', {durable: false}))
        .then((q)=>{loginQueue = q; return channel.bindQueue('login.auth', 'auth', 'login.auth')})
        .then(()=>{

            channel.consume('login.auth', (msg: auth.loginMessage)=>{
                var content = JSON.parse(msg.content.toString());
                channel.ack(msg);
                if (content.login === 'a') {
                    var token = jwt.sign({
                        iss: 'a'
                    }, 'shhhhhhared-secret');
                    channel.publish('auth', 'token.auth', new Buffer(JSON.stringify({
                        token: token,
                        login: content.login
                    })));
                } else {
                    channel.publish('auth', 'token.auth', new Buffer(JSON.stringify({
                        ERROR: 'Incorrect',
                        code: 401,
                        login: content.login
                    })));
                }
            });

        })
        .catch((e)=>{
            console.error(e);
        });

    console.log('ok');

};
開發者ID:Antonio-Lopez,項目名稱:angularjs-requirejs-typescript,代碼行數:41,代碼來源:auth.ts

示例7: Observable

    return new Observable(o => {
      let conn;
      connect(this.config.connString)
      .then(c => conn = c && c.createChannel())
      .then(ch => {
        ch.assertExchange(exchange, 'fanout', {durable: true});
        ch.assertQueue(queue, {durable: true});

        ch.bindQueue(queue, exchange, '');
        ch.consume(queue, msg => {
          let msgStr = msg.content.toString();
          ch.ack(msg);
          if (msgStr === '__done') {
            return o.complete();
          }
          o.next(msgStr);
        }, {noAck: false});
      })
      .catch(err => o.error(err));

      return () => conn && conn.close();
    });
開發者ID:jonesnc,項目名稱:gustav,代碼行數:22,代碼來源:GustavRabbit.ts

示例8:

 .flatMap(() => Rx.Observable.fromPromise(AmqpLib.connect(url, options)))
開發者ID:cboden,項目名稱:rx-amqplib,代碼行數:1,代碼來源:RxAmqpLib.ts

示例9:

 .defer(() => AmqpLib.connect(url, options))
開發者ID:RobKamstra,項目名稱:rx-amqplib,代碼行數:1,代碼來源:RxAmqpLib.ts

示例10:

const makeAmqp = config => {
  const amqp = amqplib
    .connect(config.MN_AMQP_CONNECTION)
    .then(conn => {
      process.once('SIGINT', () => {
        conn.close()
      })

      return conn.createChannel()
    })
    .then(channel => {
      channel.assertQueue(q, { durable: false })
      // Note: on Node 6 Buffer.from(msg) should be used
      channel.sendToQueue(q, Buffer.from('Hello World!'))
      // tslint:disable-next-line:no-console
      console.log("[x] Sent 'Hello World!'")
      return channel
    })
    .then(channel =>
      channel.consume(
        q,
        msg => {
          // tslint:disable-next-line:no-console
          console.log('[x] Received %s', msg ? msg.content : msg)
        },
        { noAck: true }
      )
    )
    // .then(channel => {
    //   Promise.all(
    //     Object.entries(exchanges).reduce(
    //       (acc, [exchange, types]) =>
    //         acc.concat(
    //           types.map(type =>
    //             channel.assertExchange(exchange, type, { durable: false })
    //           )
    //         ),
    //       []
    //     )
    //   ).then(() => channel);
    // })
    // .then(channel => {

    // })
    // .then(channel => {
    //   Promise.all(
    //     Object.entries(exchanges).reduce(
    //       (acc, [exchange, types]) =>
    //         acc.concat(
    //           types.map(type =>
    //             channel.assertExchange(exchange, type, { durable: false })
    //           )
    //         ),
    //       []
    //     )
    //   ).then(() => channel);
    // })
    // .then(channel => {

    // })
    .catch(console.error)
}
開發者ID:marcusnielsen,項目名稱:mn-server,代碼行數:62,代碼來源:index.ts


注:本文中的amqplib.connect函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。