I have tried creating progress with updating field as counter in database, but I have trouble since I use two and more machine with parallel process. That make database not counting in right direction. How can create right counter for every data in Queue has been process.
Have a look at RabbitMQ - Get total count of messages enqueued
This describes how you get the number of messages in the queue. With that number you should be able to calculate a progress (if you know how much entries were added to the queue in the first place)
private final static String QUEUE_NAME = "hello";
public static void main(String[] argv) throws java.io.IOException, InterruptedException, TimeoutException, KeyManagementException, NoSuchAlgorithmException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setPort(5672);
factory.setUsername("guest");
factory.setPassword("guest");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
AMQP.Queue.DeclareOk declareOk = channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(declareOk);
channel.basicPublish("", QUEUE_NAME, null, "Hello, world!".getBytes());
declareOk = channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(declareOk);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
}
The output is:
#method<queue.declare-ok>(queue=hello, message-count=1, consumer-count=0)
#method<queue.declare-ok>(queue=hello, message-count=2, consumer-count=0)
[*] Waiting for messages. To exit press CTRL+C
I'm using RabbitMq 3.6.9 and as you see, this works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.