kegaretail / react-native-rabbitmq

29 stars 56 forks source link

queue.on Receives the message only one #23

Closed CrazyMan2 closed 5 years ago

CrazyMan2 commented 5 years ago

“ react”:“ 16.8.3”, “ react-native”:“ 0.59.8”, “ react-native-rabbitmq”:“ ^ 0.6.3”

export function rabbitMqPublish(message) { exchange.publish(message,queueId,{aa:11}); } export function initRabbitMq() { connection.connect(); connection.on('error',(event)=>{ connected=false; console.log("connected fail"); }); connection.on('connected',(event)=>{ connected=true; console.log("connected success"); queue=new Queue(connection,{ name:queueId, durable:false, autoDelete:false, exclusive:false, consumer_arguments:{'x-priority':1} }); exchange = new Exchange(connection, { name: exchange_name, type: 'fanout', durable: false, autoDelete: false, exclusive: false, internal: false, confirm: true }); queue.bind(exchange, queueId);

    queue.on('message', (data) => {
        console.log('message', data);
    });
    queue.on('messages', (data) => {
        console.log('messages', data);
        //store.dispatch(actions.rabbitMessages(data));
    });
})

} rabbitMqPublish publish a message ,queue.on Receives the message only one,After unable to receive messages

Wilson-Lim commented 4 years ago

Hi @CrazyMan2 , what did u do to solve this ?

kimvex commented 3 years ago

For those who have problems with this in the future, the way to solve the problem is by editing the file: RabbitMqConnection.java on line 144 change the value of this.channel.basicQos that is set to 1 to 0

Before this.channel.basicQos(1);

After this.channel.basicQos(0);

The problem occurs because when adding the value 1 we tell it that the limit of messages in the queue is 1 and if we add 0 we tell it that it is infinite.

https://www.rabbitmq.com/consumer-prefetch.html