小编use*_*869的帖子

在一个通道中消耗多个队列

我使用 rabbitMq 来管理和处理队列。我有多个队列。它们的数量不具体。我使用直接交换来发布消息。如何仅使用一个通道使用每个队列的所有消息(基于routing_key)?此时我假设我有 5 个队列。我已经使用 for 循环并为每个队列创建一个通道。像这样:

 stuff=["shoes","pants","hats","jewels","glasses"];

  stuff.forEach(cnt => 
    {
        var ex = 'stuff';
        var cq=cnt;

        amqp
        .connect('amqp://localhost')
        .then(conn => conn.createChannel())
        .then(ch => {

            ch.assertExchange(ex, 'x-delayed-message', { durable: true, 
     arguments: { 'x-delayed-type': 'direct' } })
     return ch
             .assertQueue(cq, { durable: true })
             .then(() =>  {   ch.bindQueue(cq, ex, cq)  /*second cq is routing*/  
                 })
                  .then(() => {
                  ch.consume(cq, (msg) =>
                  {

                   console.log("['%s']  '%s'",cq, msg.content.toString()); 
                   if( msg.content.toString()!=null)
                   console.log(cq);

                          reciveMSG=JSON.parse(msg.content.toString());

                    }, { noAck: true });
               }); 
         }) 


     });
Run Code Online (Sandbox Code Playgroud)

但我只想用一个频道来做。因为它更乐观并且使用更少的内存(我不知道这是真的还是假的!)。有没有办法处理非特定数量的队列?

rabbitmq node.js

4
推荐指数
1
解决办法
3429
查看次数

如何使用apollo服务器对graphQl中的数据进行排序?

我使用 apollo-server 编写 graphql 代码。在发送数据之前,我想根据可选字段和过滤器对数据进行某种排序,并且我需要知道编写代码的正确方法?graphql中有没有一种方法可以自动对我的数据进行排序?

我使用lodash进行排序,我认为在我搜索后我看到了prisma但它们没有优化,但我的数据是由另一个不在数据库中的 api 返回的。我需要像棱镜这样的东西。

我的代码是这样的,我想根据查询中的名称或姓氏对书籍进行排序,但在 api 返回的实际书籍对象中。

const { ApolloServer, gql, } = require('apollo-server');

const books = [
{
    title: 'Harry Potter and the Chamber of Secrets',
    authors: [{"name":"a1", "lastName":"aa1"},{"name":"b1", "lastName":"bb1"},{"name":"c1", "lastName":"cc1"}]
  },
  {
    title: 'Jurassic Park',
    authors: [{"name":"a" ,"lastName":"aa"},{"name":"b", "lastName":"bb"},{"name":"c", "lastName":"cc"}]
  },
];
const typeDefs = gql`

type Book {
    title: String
    authors: [Author]
  }
type Query{
    books: [Book]
  }
type Author{
name: String
lastName: String
}
  `;
const resolvers = { …
Run Code Online (Sandbox Code Playgroud)

sorting node.js apollo graphql-js

3
推荐指数
1
解决办法
6435
查看次数

c#中未知大小的数组

我在C#编程,我想定义一个我不知道它的大小的数组,因为我想从文件中读取一些东西,我不知道该文件中的元素数量.这是我的代码,我有"x"数组的问题!

using (TextReader reader = File.OpenText("Numbers.txt"))
{
    string[] bits;
    string text = reader.ReadLine();
    int i ,j=0;
    int [] x;
    while (text != null)
    {
        i = 0;
        bits = text.Split(' ');

        while (bits[i] != null)
        {
            x[j] = int.Parse(bits[i]);
            i++;
            j++;
        }

        text = reader.ReadLine();
    }

}
Run Code Online (Sandbox Code Playgroud)

之后我会得到这个错误"使用未分配的局部变量'x'"我不知道该怎么办!! 请帮我...

c# arrays

0
推荐指数
1
解决办法
2447
查看次数

标签 统计

node.js ×2

apollo ×1

arrays ×1

c# ×1

graphql-js ×1

rabbitmq ×1

sorting ×1