0
Has anyone here ever worked with rabbitmq implementing java for messaging? I need your help.
I need to recover the number of messages in a queue in Rabbitmq. This is my class, it is a task, in which it is consuming the messages:
@Override
public void run() {
ProtocolInternalMessageFacade protocolInternalFacade = new ProtocolInternalMessageFacade();
while (true) {
try {
if (CheckServer.hostAvailabilityCheck()) {
/*
* quando eu passo o mouse em cima desse queueingConsumer,
* é ai que me mostra a propriedade size, se por exemplo estiver 2
* mensagens nessa propriedade, mostra Size = 2
*/
QueueingConsumer queueingConsumer = Consumer.getQueueingConsumer(QUEUE_NAME);
QueueingConsumer.Delivery delivery = null;
try {
QueueingConsumer.Delivery deliveryTmp;
/*
* aqui eu fiz o seguinte: por exemplo coloquei um for de um a
* 5(por isso eu queria essa quantidade de mensagem que tem nessa
* fila, para que fazer esse for de acordo com essa quantidade.)
* Se eu estiver por exemplo 2 registros, ele sempre irá pegar
* esse ultimo registro, salvar e mostrar para mim.
*/
for (int i = 0; i < 5; i++){
deliveryTmp = queueingConsumer.nextDelivery(5);
if(deliveryTmp != null){
delivery = deliveryTmp;
}
}
} catch (InterruptedException | ShutdownSignalException |
ConsumerCancelledException e) {
e.printStackTrace(System.err);
LOGGER.trace(ConvertStackTrace.getStringFromStackTrace(e));
}
if (delivery != null) {
ProtocolInternalMessage protocolInternalMessage =
(ProtocolInternalMessage) ConvertData.fromBytes(delivery.getBody());
protocolInternalFacade.insert(protocolInternalMessage);
}
Consumer.getChannel().close();
Consumer.getConnection().close();
} else {
System.out.println("Server Not Found. Please, contact the administrator");
LOGGER.error("Error connect server");
}
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException | ShutdownSignalException |
ConsumerCancelledException | ServiceException | IOException e) {
e.printStackTrace(System.err);
LOGGER.trace(ConvertStackTrace.getStringFromStackTrace(e));
}
}
}
And what help you need?
– Bruno César
I need to know if there’s any way I can get the amount of message that comes in this line.. for example: I sent two messages, I want to get this amount in the client .
– Ivan
It’s possible to do that?
– Ivan
You can know how many messages are in the queue, see
DeclareOk
. That’s right?– Bruno César
So, I have this code below, where in my queueingConsumer has a size when I debug.. I wanted to get this amount.
– Ivan
Queueingconsumer queueingConsumer = Consumer.getQueingConsumer(QUEUE_NAME); Queueingconsumer.Delivery = null;
– Ivan
This size is in which object, in the properties? It’s hard to help without knowing the details, consider editing your question with your scenario, what you’ve tried, observations you think are relevant to who’s helping you, something that makes it possible to reproduce and propose a solution to you. Behold How to ask a good question?
– Bruno César
I edited my question. I put the code, maybe it’s clearer now.
– Ivan
Let’s go continue this discussion in chat.
– Ivan