Retrieving mulitple messages from a single rabbit MQ queue using java [closed]
I know we can get a single message from the queue using basic.get()
. But I'm not able to retrieve all the messages (maybe 10) in the queue using that. I got some answers to use basic.consume()
but not sure how to use it and fetch the messages in queue. can some one help me.
I am new to rabbit mq.
java rabbitmq message-queue
closed as off-topic by theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor Nov 13 '18 at 15:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I know we can get a single message from the queue using basic.get()
. But I'm not able to retrieve all the messages (maybe 10) in the queue using that. I got some answers to use basic.consume()
but not sure how to use it and fetch the messages in queue. can some one help me.
I am new to rabbit mq.
java rabbitmq message-queue
closed as off-topic by theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor Nov 13 '18 at 15:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor
If this question can be reworded to fit the rules in the help center, please edit the question.
Please see the response from @Gabriele! Don't usebasic.get
! You should also read about QoS / Prefetch.
– Luke Bakken
Nov 12 '18 at 10:01
@LukeBakken- there is nothing wrong with usingbasic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.
– theMayer
Nov 13 '18 at 13:37
add a comment |
I know we can get a single message from the queue using basic.get()
. But I'm not able to retrieve all the messages (maybe 10) in the queue using that. I got some answers to use basic.consume()
but not sure how to use it and fetch the messages in queue. can some one help me.
I am new to rabbit mq.
java rabbitmq message-queue
I know we can get a single message from the queue using basic.get()
. But I'm not able to retrieve all the messages (maybe 10) in the queue using that. I got some answers to use basic.consume()
but not sure how to use it and fetch the messages in queue. can some one help me.
I am new to rabbit mq.
java rabbitmq message-queue
java rabbitmq message-queue
edited Nov 13 '18 at 20:24
marc_s
571k12811031251
571k12811031251
asked Nov 12 '18 at 2:53
Deepak S
46
46
closed as off-topic by theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor Nov 13 '18 at 15:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor Nov 13 '18 at 15:25
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – theMayer, DaveyDaveDave, greg-449, cнŝdk, Fildor
If this question can be reworded to fit the rules in the help center, please edit the question.
Please see the response from @Gabriele! Don't usebasic.get
! You should also read about QoS / Prefetch.
– Luke Bakken
Nov 12 '18 at 10:01
@LukeBakken- there is nothing wrong with usingbasic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.
– theMayer
Nov 13 '18 at 13:37
add a comment |
Please see the response from @Gabriele! Don't usebasic.get
! You should also read about QoS / Prefetch.
– Luke Bakken
Nov 12 '18 at 10:01
@LukeBakken- there is nothing wrong with usingbasic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.
– theMayer
Nov 13 '18 at 13:37
Please see the response from @Gabriele! Don't use
basic.get
! You should also read about QoS / Prefetch.– Luke Bakken
Nov 12 '18 at 10:01
Please see the response from @Gabriele! Don't use
basic.get
! You should also read about QoS / Prefetch.– Luke Bakken
Nov 12 '18 at 10:01
@LukeBakken- there is nothing wrong with using
basic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.– theMayer
Nov 13 '18 at 13:37
@LukeBakken- there is nothing wrong with using
basic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.– theMayer
Nov 13 '18 at 13:37
add a comment |
1 Answer
1
active
oldest
votes
The best way to retrive messages is to use basic.consume()
, there are several examples around.
But I suggest to start from here:
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
This is the code to consume messages using basic.consume
:
String QUEUE_NAME= "hello"
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The best way to retrive messages is to use basic.consume()
, there are several examples around.
But I suggest to start from here:
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
This is the code to consume messages using basic.consume
:
String QUEUE_NAME= "hello"
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
add a comment |
The best way to retrive messages is to use basic.consume()
, there are several examples around.
But I suggest to start from here:
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
This is the code to consume messages using basic.consume
:
String QUEUE_NAME= "hello"
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
add a comment |
The best way to retrive messages is to use basic.consume()
, there are several examples around.
But I suggest to start from here:
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
This is the code to consume messages using basic.consume
:
String QUEUE_NAME= "hello"
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
The best way to retrive messages is to use basic.consume()
, there are several examples around.
But I suggest to start from here:
https://www.rabbitmq.com/tutorials/tutorial-one-java.html
This is the code to consume messages using basic.consume
:
String QUEUE_NAME= "hello"
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope,
AMQP.BasicProperties properties, byte body)
throws IOException {
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
answered Nov 12 '18 at 7:45
Gabriele
14.4k42233
14.4k42233
add a comment |
add a comment |
Please see the response from @Gabriele! Don't use
basic.get
! You should also read about QoS / Prefetch.– Luke Bakken
Nov 12 '18 at 10:01
@LukeBakken- there is nothing wrong with using
basic.get
- it is a pull vs push approach. Many people find a pull approach to match up better with their consuming logic.– theMayer
Nov 13 '18 at 13:37