• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript amqplib.connect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript amqplib.Channel类代码示例发布时间:2022-05-28
下一篇:
TypeScript amqp10.Client类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap