当前位置: 首页>>代码示例>>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;未经允许,请勿转载。