private void runIt() throws IOException { Channel channel = _connection.createChannel(); String queueName = "test queue"; channel.queueDeclare(queueName, true, false, false, null); String exchangeName = "test completion"; channel.exchangeDeclare(exchangeName, "fanout", false, false, null); String completionQueue = channel.queueDeclare().getQueue(); channel.queueBind(completionQueue, exchangeName, ""); LatencyExperimentConsumer callback = new LatencyExperimentConsumer(channel, queueName); callback._autoAck = this._autoAck; channel.basicConsume(queueName, _autoAck, callback); channel.basicConsume(completionQueue, true, "completion", callback); callback.report(_writeStats); System.out.println("Deleting test queue."); channel.queueDelete(queueName); System.out.println("Deleting completion queue."); channel.queueDelete(completionQueue); System.out.println("Closing the channel."); channel.close(); System.out.println("Closing the connection."); _connection.close(); System.out.println("Leaving ConsumerMain.run()."); }
// bug 26552 public void testServerNamedTransientAutoDeleteQueueAndBindingRecovery() throws IOException, InterruptedException, TimeoutException { String x = "tmp-fanout"; Channel ch = connection.createChannel(); ch.exchangeDelete(x); ch.exchangeDeclare(x, "fanout"); String q = ch.queueDeclare("", false, false, true, null).getQueue(); final AtomicReference<String> nameBefore = new AtomicReference<String>(q); final AtomicReference<String> nameAfter = new AtomicReference<String>(); final CountDownLatch listenerLatch = new CountDownLatch(1); ((AutorecoveringConnection) connection) .addQueueRecoveryListener( new QueueRecoveryListener() { @Override public void queueRecovered(String oldName, String newName) { nameBefore.set(oldName); nameAfter.set(newName); listenerLatch.countDown(); } }); ch.queueBind(nameBefore.get(), x, ""); restartPrimaryAndWaitForRecovery(); expectChannelRecovery(ch); ch.confirmSelect(); ch.exchangeDeclare(x, "fanout"); ch.basicPublish(x, "", null, "msg".getBytes()); waitForConfirms(ch); AMQP.Queue.DeclareOk ok = ch.queueDeclarePassive(nameAfter.get()); assertEquals(1, ok.getMessageCount()); ch.queueDelete(nameAfter.get()); ch.exchangeDelete(x); }
public void testClientNamedQueueBindingRecovery() throws IOException, InterruptedException, TimeoutException { String q = "java-client.test.recovery.q2"; String x = "tmp-fanout"; Channel ch = connection.createChannel(); ch.queueDelete(q); ch.exchangeDelete(x); ch.exchangeDeclare(x, "fanout"); declareClientNamedAutoDeleteQueue(ch, q); ch.queueBind(q, x, ""); closeAndWaitForRecovery(); expectChannelRecovery(ch); expectAutoDeleteQueueAndBindingRecovery(ch, x, q); ch.queueDelete(q); ch.exchangeDelete(x); }
// bug 26552 public void testClientNamedTransientAutoDeleteQueueAndBindingRecovery() throws IOException, InterruptedException, TimeoutException { String q = UUID.randomUUID().toString(); String x = "tmp-fanout"; Channel ch = connection.createChannel(); ch.queueDelete(q); ch.exchangeDelete(x); ch.exchangeDeclare(x, "fanout"); ch.queueDeclare(q, false, false, true, null); ch.queueBind(q, x, ""); restartPrimaryAndWaitForRecovery(); expectChannelRecovery(ch); ch.confirmSelect(); ch.queuePurge(q); ch.exchangeDeclare(x, "fanout"); ch.basicPublish(x, "", null, "msg".getBytes()); waitForConfirms(ch); AMQP.Queue.DeclareOk ok = ch.queueDeclare(q, false, false, true, null); assertEquals(1, ok.getMessageCount()); ch.queueDelete(q); ch.exchangeDelete(x); }
protected void testClientNamedQueueRecoveryWith(String q, boolean noWait) throws IOException, InterruptedException, TimeoutException { Channel ch = connection.createChannel(); if (noWait) { declareClientNamedQueueNoWait(ch, q); } else { declareClientNamedQueue(ch, q); } closeAndWaitForRecovery(); expectChannelRecovery(ch); expectQueueRecovery(ch, q); ch.queueDelete(q); }
public void testDeclarationOfManyAutoDeleteExchangesWithTransientQueuesThatAreDeleted() throws IOException, TimeoutException { Channel ch = connection.createChannel(); assertRecordedExchanges(connection, 0); for (int i = 0; i < 5000; i++) { String x = UUID.randomUUID().toString(); ch.exchangeDeclare(x, "fanout", false, true, null); String q = ch.queueDeclare().getQueue(); ch.queueBind(q, x, "doesn't matter"); ch.queueDelete(q); } assertRecordedExchanges(connection, 0); ch.close(); }
@Override public void amqpUnRegister(User user) throws Exception { Channel channel = USER_CHANNEL.get(user); if (channel != null) { logger.info("###Unregistering user [" + user.getUsername() + "] ... "); // delete queue channel.queueDelete("USER_".concat(String.valueOf(user.hashCode()))); USER_CHANNEL.remove(user); // close channel channel.close(); } logger.info("###Unregistering user [" + user.getUsername() + "] Success !"); }
public void clean() throws IOException { System.out.println("Starting app"); ApplicationContext ctx = new ClassPathXmlApplicationContext("/properties-context.xml", "/rabbitmq-context.xml"); RabbitMqChannelManager rabbitMqChannelManager = ctx.getBean(RabbitMqChannelManager.class); Channel channel = rabbitMqChannelManager.currentChannel(); Properties p = new Properties(); p.load(ctx.getResource("classpath:/application.properties").getInputStream()); System.out.println("Deleting queue"); channel.queueDelete(p.getProperty("rabbitmq.queue")); System.out.println("Done"); }
@Override public void run() { int i = 0; while (true) { try { Channel c = conn.createChannel(); if ((i++ % 1000) == 0) { System.out.println("Opened " + this.toString() + ", i = " + i); } c.queueDelete("non-existing-" + r.nextInt()); } catch (IOException e) { } } }