All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testvagrant.optimuscloud.messaging.SessionQueueReader Maven / Gradle / Ivy

Go to download

The Java Client provides access to Optimus cloud for all java based projects.

There is a newer version: 1.1.0
Show newest version
package com.testvagrant.optimuscloud.messaging;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class SessionQueueReader {

    public synchronized String  consumeMessage(String routingKey) throws IOException, TimeoutException {
        Channel channel = SessionConnection.getInstance().getChannel();
        synchronized (this) {
            try {
                GetResponse getResponse = channel.basicGet(routingKey, false);
                return new String(getResponse.getBody(),"UTF-8");
            } catch (Exception e) {
                return null;
            }
        }
    }

    public synchronized boolean queueHasAMessage(String queue_name) throws IOException, TimeoutException {
        Channel channel = SessionConnection.getInstance().getChannel();
        long messageCount = channel.messageCount(queue_name);
        return messageCount>0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy