// 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); }
@Override public void enmq(String exchange, Channel ch, MQPacket re) throws IOException { byte[] data = re.data; if (LOG.isDebugEnabled()) { LOG.debug("send data to mq, length:" + data.length); } ch.basicPublish(exchange, "anomoy", MessageProperties.PERSISTENT_BASIC, data); }
private void expectExchangeRecovery(Channel ch, String x) throws IOException, InterruptedException, TimeoutException { ch.confirmSelect(); String q = ch.queueDeclare().getQueue(); final String rk = "routing-key"; ch.queueBind(q, x, rk); ch.basicPublish(x, rk, null, "msg".getBytes()); waitForConfirms(ch); ch.exchangeDeclarePassive(x); }
private void expectQueueRecovery(Channel ch, String q) throws IOException, InterruptedException, TimeoutException { ch.confirmSelect(); ch.queuePurge(q); AMQP.Queue.DeclareOk ok1 = declareClientNamedQueue(ch, q); assertEquals(0, ok1.getMessageCount()); ch.basicPublish("", q, null, "msg".getBytes()); waitForConfirms(ch); AMQP.Queue.DeclareOk ok2 = declareClientNamedQueue(ch, q); assertEquals(1, ok2.getMessageCount()); }
/** Private API - Process a single request. Called from mainloop(). */ public void processRequest(QueueingConsumer.Delivery request) throws IOException { AMQP.BasicProperties requestProperties = request.getProperties(); String correlationId = requestProperties.getCorrelationId(); String replyTo = requestProperties.getReplyTo(); if (correlationId != null && replyTo != null) { AMQP.BasicProperties replyProperties = new AMQP.BasicProperties.Builder().correlationId(correlationId).build(); byte[] replyBody = handleCall(request, replyProperties); _channel.basicPublish("", replyTo, replyProperties, replyBody); } else { handleCast(request); } }
public static void t3() throws Exception { Channel channel = generateChannel(); channel.exchangeDeclare(TestAmqp.PingExchangerName, "direct", true, false, null); channel.queueDeclare("rpc", false, false, false, null); // channel.queueBind(TestAmqp.TopicQueueName, TestAmqp.TopicExchangerName, // TestAmqp.RouteingName); // channel.queueBind(TestAmqp.TopicQueueName, TestAmqp.TopicExchangerName, "*"); channel.queueBind("rpc", TestAmqp.PingExchangerName, "ping"); QueueingConsumer queueingConsumer = new QueueingConsumer(channel); channel.basicConsume("rpc", false, queueingConsumer); while (true) { QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery(); System.out.println("log: " + new String(delivery.getBody())); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); System.out.println("reply to :" + delivery.getProperties().getReplyTo()); channel.basicPublish("", delivery.getProperties().getReplyTo(), null, "asfasdfas".getBytes()); } }
// 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); }
public void testBasicAckAfterChannelRecovery() throws IOException, InterruptedException, TimeoutException { final AtomicInteger consumed = new AtomicInteger(0); int n = 5; final CountDownLatch latch = new CountDownLatch(n); Consumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery( String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { try { if (consumed.intValue() > 0 && consumed.intValue() % 4 == 0) { CountDownLatch recoveryLatch = prepareForRecovery(connection); Host.closeConnection((AutorecoveringConnection) connection); ConnectionRecovery.wait(recoveryLatch); } channel.basicAck(envelope.getDeliveryTag(), false); } catch (InterruptedException e) { // ignore } finally { consumed.incrementAndGet(); latch.countDown(); } } }; String q = channel.queueDeclare().getQueue(); channel.basicConsume(q, consumer); AutorecoveringConnection publishingConnection = newRecoveringConnection(false); Channel publishingChannel = publishingConnection.createChannel(); for (int i = 0; i < n; i++) { publishingChannel.basicPublish("", q, null, "msg".getBytes()); } wait(latch); publishingConnection.abort(); }
@Override public void send(IncidentReport iReport) throws IOException, MarshalException, ValidationException { channel.basicPublish("", QUEUE_NAME, null, msgConverter.convertJavaToXML(iReport).getBytes()); }