Package org.springframework.amqp.rabbit.support

Examples of org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl


        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);
    }
View Full Code Here


    Connection mockConnection = mock(Connection.class);
    Channel mockChannel = mock(Channel.class);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    doReturn(new PublisherCallbackChannelImpl(mockChannel)).when(mockConnection).createChannel();

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setPublisherConfirms(true);
    final RabbitTemplate template = new RabbitTemplate(ccf);
View Full Code Here

    when(mockChannel1.getNextPublishSeqNo()).thenReturn(1L, 2L, 3L, 4L);
    when(mockChannel2.getNextPublishSeqNo()).thenReturn(1L, 2L, 3L, 4L);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    PublisherCallbackChannelImpl channel1 = new PublisherCallbackChannelImpl(mockChannel1);
    PublisherCallbackChannelImpl channel2 = new PublisherCallbackChannelImpl(mockChannel2);
    when(mockConnection.createChannel()).thenReturn(channel1).thenReturn(channel2);

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setPublisherConfirms(true);
    ccf.setChannelCacheSize(3);
View Full Code Here

    Connection mockConnection = mock(Connection.class);
    Channel mockChannel = mock(Channel.class);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    doReturn(new PublisherCallbackChannelImpl(mockChannel)).when(mockConnection).createChannel();

    final AtomicInteger count = new AtomicInteger();
    doAnswer(new Answer<Object>(){
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
View Full Code Here

    Connection mockConnection = mock(Connection.class);
    Channel mockChannel = mock(Channel.class);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    PublisherCallbackChannelImpl callbackChannel = new PublisherCallbackChannelImpl(mockChannel);
    when(mockConnection.createChannel()).thenReturn(callbackChannel);

    final AtomicInteger count = new AtomicInteger();
    doAnswer(new Answer<Object>(){
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        return count.incrementAndGet();
      }}).when(mockChannel).getNextPublishSeqNo();

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setPublisherConfirms(true);
    final RabbitTemplate template = new RabbitTemplate(ccf);

    final CountDownLatch latch = new CountDownLatch(2);
    template.setConfirmCallback(new ConfirmCallback() {

      @Override
      public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
          latch.countDown();
        }
      }
    });
    template.convertAndSend(ROUTE, (Object) "message", new CorrelationData("abc"));
    template.convertAndSend(ROUTE, (Object) "message", new CorrelationData("def"));
    callbackChannel.handleAck(2, true);
    assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
    Collection<CorrelationData> unconfirmed = template.getUnconfirmed(0);
    assertNull(unconfirmed);
  }
View Full Code Here

    Connection mockConnection = mock(Connection.class);
    Channel mockChannel = mock(Channel.class);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    PublisherCallbackChannelImpl callbackChannel = new PublisherCallbackChannelImpl(mockChannel);
    when(mockConnection.createChannel()).thenReturn(callbackChannel);

    final AtomicInteger count = new AtomicInteger();
    doAnswer(new Answer<Object>(){
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        return count.incrementAndGet();
      }
    }).when(mockChannel).getNextPublishSeqNo();

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setPublisherConfirms(true);
    final RabbitTemplate template1 = new RabbitTemplate(ccf);

    final Set<String> confirms = new HashSet<String>();
    final CountDownLatch latch1 = new CountDownLatch(1);
    template1.setConfirmCallback(new ConfirmCallback() {

      @Override
      public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
          confirms.add(correlationData.getId() + "1");
          latch1.countDown();
        }
      }
    });
    final RabbitTemplate template2 = new RabbitTemplate(ccf);

    final CountDownLatch latch2 = new CountDownLatch(1);
    template2.setConfirmCallback(new ConfirmCallback() {

      @Override
      public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
          confirms.add(correlationData.getId() + "2");
          latch2.countDown();
        }
      }
    });
    template1.convertAndSend(ROUTE, (Object) "message", new CorrelationData("abc"));
    template2.convertAndSend(ROUTE, (Object) "message", new CorrelationData("def"));
    template2.convertAndSend(ROUTE, (Object) "message", new CorrelationData("ghi"));
    callbackChannel.handleAck(3, true);
    assertTrue(latch1.await(1000, TimeUnit.MILLISECONDS));
    assertTrue(latch2.await(1000, TimeUnit.MILLISECONDS));
    Collection<CorrelationData> unconfirmed1 = template1.getUnconfirmed(0);
    assertNull(unconfirmed1);
    Collection<CorrelationData> unconfirmed2 = template2.getUnconfirmed(0);
View Full Code Here

    Channel mockChannel = mock(Channel.class);
    when(mockChannel.getNextPublishSeqNo()).thenReturn(1L, 2L, 3L, 4L);

    when(mockConnectionFactory.newConnection((ExecutorService) null)).thenReturn(mockConnection);
    when(mockConnection.isOpen()).thenReturn(true);
    final PublisherCallbackChannelImpl channel = new PublisherCallbackChannelImpl(mockChannel);
    when(mockConnection.createChannel()).thenReturn(channel);

    CachingConnectionFactory ccf = new CachingConnectionFactory(mockConnectionFactory);
    ccf.setPublisherConfirms(true);
    ccf.setChannelCacheSize(3);
    final RabbitTemplate template = new RabbitTemplate(ccf);

    final CountDownLatch first2SentOnThread1Latch = new CountDownLatch(1);
    final CountDownLatch delayAckProcessingLatch = new CountDownLatch(1);
    final CountDownLatch startedProcessingMultiAcksLatch = new CountDownLatch(1);
    final CountDownLatch waitForAll3AcksLatch = new CountDownLatch(3);
    final CountDownLatch allSentLatch = new CountDownLatch(1);
    final AtomicInteger acks = new AtomicInteger();
    template.setConfirmCallback(new ConfirmCallback() {

      @Override
      public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        try {
          startedProcessingMultiAcksLatch.countDown();
          // delay processing here; ensures thread 2 put would be concurrent
          delayAckProcessingLatch.await(2, TimeUnit.SECONDS);
          // only delay first time through
          delayAckProcessingLatch.countDown();
          waitForAll3AcksLatch.countDown();
          acks.incrementAndGet();
        }
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    });
    Executors.newSingleThreadExecutor().execute(new Runnable() {
      @Override
      public void run() {
        template.convertAndSend(ROUTE, (Object) "message", new CorrelationData("abc"));
        template.convertAndSend(ROUTE, (Object) "message", new CorrelationData("def"));
        first2SentOnThread1Latch.countDown();
      }
    });
    Executors.newSingleThreadExecutor().execute(new Runnable() {
      @Override
      public void run() {
        try {
          startedProcessingMultiAcksLatch.await();
          template.convertAndSend(ROUTE, (Object) "message", new CorrelationData("ghi"));
          allSentLatch.countDown();
        }
        catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    });
    assertTrue(first2SentOnThread1Latch.await(10, TimeUnit.SECONDS));
    // there should be no concurrent execution exception here
    channel.handleAck(2, true);
    assertTrue(allSentLatch.await(10, TimeUnit.SECONDS));
    channel.handleAck(3, false);
    assertTrue(waitForAll3AcksLatch.await(10, TimeUnit.SECONDS));
    assertEquals(3, acks.get());


    // 3.3.1 client
    channel.basicConsume("foo", false, (Map) null, null);
    verify(mockChannel).basicConsume("foo", false, (Map) null, null);

    channel.basicQos(3, false);
    verify(mockChannel).basicQos(3, false);

    doReturn(true).when(mockChannel).flowBlocked();
    assertTrue(channel.flowBlocked());

    try {
      channel.flow(true);
      fail("Expected exception");
    }
    catch (UnsupportedOperationException e) {}

    try {
      channel.getFlow();
      fail("Expected exception");
    }
    catch (UnsupportedOperationException e) {}

    // 3.2.4 client
View Full Code Here

TOP

Related Classes of org.springframework.amqp.rabbit.support.PublisherCallbackChannelImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.