Esempio n. 1
0
 // 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);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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 Channel doCreateBareChannel(
     ChannelCachingConnectionProxy connection, boolean transactional) {
   Channel channel = connection.createBareChannel(transactional);
   if (this.publisherConfirms) {
     try {
       channel.confirmSelect();
     } catch (IOException e) {
       logger.error("Could not configure the channel to receive publisher confirms", e);
     }
   }
   if (this.publisherConfirms || this.publisherReturns) {
     if (!(channel instanceof PublisherCallbackChannelImpl)) {
       channel = new PublisherCallbackChannelImpl(channel);
     }
   }
   if (channel != null) {
     channel.addShutdownListener(this);
   }
   return channel;
 }
Esempio n. 5
0
 // 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);
 }
Esempio n. 6
0
  @Override
  protected boolean publishImpl(
      TransportMessageBundle bundle, TransportPublishProperties properties)
      throws IOException, TimeoutException, InterruptedException {
    AMQPPublishProperties publishProperties = (AMQPPublishProperties) properties;
    AMQPMessageBundle messageBundle = (AMQPMessageBundle) bundle;

    if (publishProperties.isConfirmEnabled()) {
      channel.confirmSelect();
    }

    channel.basicPublish(
        publishProperties.getExchange(),
        publishProperties.getRoutingKey(),
        messageBundle.getBasicProperties(),
        messageBundle.getBody());

    if (publishProperties.isConfirmEnabled()) {
      return channel.waitForConfirms(publishProperties.getTimeout());
    }

    return true;
  }