- Timestamp:
- 05/23/13 21:37:28 (11 years ago)
- Location:
- trunk/objectmq
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/objectmq/.classpath
r9 r22 6 6 <classpathentry kind="lib" path="lib/commons-cli-1.1.jar"/> 7 7 <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> 9 13 <classpathentry kind="lib" path="lib/kryo-2.21-all.jar"/> 10 14 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> -
trunk/objectmq/src/omq/common/broker/Broker.java
r21 r22 12 12 import omq.common.util.Environment; 13 13 import omq.common.util.OmqConnectionFactory; 14 import omq.common.util.ParameterQueue; 14 15 import omq.common.util.Serializer; 15 16 import omq.exception.EnvironmentException; 17 import omq.exception.InitBrokerException; 16 18 import omq.exception.RemoteException; 17 19 import omq.exception.SerializerException; … … 20 22 import com.rabbitmq.client.Channel; 21 23 import com.rabbitmq.client.Connection; 24 import com.rabbitmq.client.QueueingConsumer; 25 import com.rabbitmq.client.QueueingConsumer.Delivery; 22 26 23 27 public class Broker { … … 33 37 connection = OmqConnectionFactory.getNewConnection(env); 34 38 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 } 35 46 } 36 47 } … … 104 115 } 105 116 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 } 106 145 } -
trunk/objectmq/src/omq/common/util/OmqConnectionFactory.java
r14 r22 17 17 public class OmqConnectionFactory { 18 18 private static Connection connection; 19 private static int connectionTimeout = 2 * 1000; 19 20 20 21 public static void init(Properties env) throws KeyManagementException, NoSuchAlgorithmException, IOException { … … 41 42 factory.setHost(host); 42 43 factory.setPort(port); 44 factory.setConnectionTimeout(connectionTimeout); 43 45 if (ssl) { 44 46 factory.useSslProtocol();
Note: See TracChangeset
for help on using the changeset viewer.