Package com.abiquo.commons.amqp.util

Source Code of com.abiquo.commons.amqp.util.RabbitMQUtils

/**
* Copyright (C) 2008 - Abiquo Holdings S.L. All rights reserved.
*
* Please see /opt/abiquo/tomcat/webapps/legal/ on Abiquo server
* or contact contact@abiquo.com for licensing information.
*/
package com.abiquo.commons.amqp.util;

import com.abiquo.commons.amqp.AMQPProperties;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
* A set of utility methods related to RabbitMQ server.
*
* @author eruiz@abiquo.com
*/
public class RabbitMQUtils
{
    private static final ConnectionFactory connectionFactory = new ConnectionFactory();

    static
    {
        connectionFactory.setHost(AMQPProperties.getBrokerHost());
        connectionFactory.setPort(AMQPProperties.getBrokerPort());
        connectionFactory.setUsername(AMQPProperties.getUserName());
        connectionFactory.setPassword(AMQPProperties.getPassword());
        connectionFactory.setVirtualHost(AMQPProperties.getVirtualHost());
        connectionFactory.setConnectionTimeout(AMQPProperties.getConnectionTimeout());
        connectionFactory.setRequestedHeartbeat(AMQPProperties.getRequestedHeartbeat());
    }

    public static boolean pingRabbitMQ()
    {
        try
        {
            final Connection connection = connectionFactory.newConnection();
            try
            {
                return connection.isOpen();
            }
            finally
            {
                connection.close();
            }
        }
        catch (Exception e)
        {
            return false;
        }
    }
}
TOP

Related Classes of com.abiquo.commons.amqp.util.RabbitMQUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.