Changeset 22


Ignore:
Timestamp:
05/23/13 21:37:28 (11 years ago)
Author:
stoda
Message:
 
Location:
trunk/objectmq
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/objectmq/.classpath

    r9 r22  
    66        <classpathentry kind="lib" path="lib/commons-cli-1.1.jar"/>
    77        <classpathentry kind="lib" path="lib/commons-io-1.2.jar"/>
    8         <classpathentry kind="lib" path="lib/rabbitmq-client.jar"/>
     8        <classpathentry kind="lib" path="lib/rabbitmq-client.jar">
     9                <attributes>
     10                        <attribute name="javadoc_location" value="file:/home/sergi/Documentos/Sergi/Java/workspace/objectmq/lib/rabbitmq-java-client-javadoc-3.0.1/"/>
     11                </attributes>
     12        </classpathentry>
    913        <classpathentry kind="lib" path="lib/kryo-2.21-all.jar"/>
    1014        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
  • trunk/objectmq/src/omq/common/broker/Broker.java

    r21 r22  
    1212import omq.common.util.Environment;
    1313import omq.common.util.OmqConnectionFactory;
     14import omq.common.util.ParameterQueue;
    1415import omq.common.util.Serializer;
    1516import omq.exception.EnvironmentException;
     17import omq.exception.InitBrokerException;
    1618import omq.exception.RemoteException;
    1719import omq.exception.SerializerException;
     
    2022import com.rabbitmq.client.Channel;
    2123import com.rabbitmq.client.Connection;
     24import com.rabbitmq.client.QueueingConsumer;
     25import com.rabbitmq.client.QueueingConsumer.Delivery;
    2226
    2327public class Broker {
     
    3337                        connection = OmqConnectionFactory.getNewConnection(env);
    3438                        channel = connection.createChannel();
     39                        try {
     40                                tryConnection(env);
     41                        } catch (Exception e) {
     42                                channel.close();
     43                                connection.close();
     44                                throw new InitBrokerException("The connection didn't work");
     45                        }
    3546                }
    3647        }
     
    104115        }
    105116
     117        public static void tryConnection(Properties env) throws Exception {
     118                Channel channel = connection.createChannel();
     119                String message = "ping";
     120
     121                String exchange = env.getProperty(ParameterQueue.USER_NAME);
     122                String queueName = exchange + "ping";
     123                String routingKey = "routingKey";
     124
     125                channel.exchangeDeclare(exchange, "direct");
     126                channel.queueDeclare(queueName, false, false, false, null);
     127                channel.queueBind(queueName, exchange, routingKey);
     128
     129                channel.basicPublish(exchange, routingKey, null, message.getBytes());
     130
     131                QueueingConsumer consumer = new QueueingConsumer(channel);
     132
     133                channel.basicConsume(queueName, true, consumer);
     134                Delivery delivery = consumer.nextDelivery(1000);
     135
     136                channel.exchangeDelete(exchange);
     137                channel.queueDelete(queueName);
     138
     139                channel.close();
     140
     141                if (!message.equalsIgnoreCase(new String(delivery.getBody()))) {
     142                        throw new Exception();
     143                }
     144        }
    106145}
  • trunk/objectmq/src/omq/common/util/OmqConnectionFactory.java

    r14 r22  
    1717public class OmqConnectionFactory {
    1818        private static Connection connection;
     19        private static int connectionTimeout = 2 * 1000;
    1920
    2021        public static void init(Properties env) throws KeyManagementException, NoSuchAlgorithmException, IOException {
     
    4142                factory.setHost(host);
    4243                factory.setPort(port);
     44                factory.setConnectionTimeout(connectionTimeout);
    4345                if (ssl) {
    4446                        factory.useSslProtocol();
Note: See TracChangeset for help on using the changeset viewer.