當前位置: 首頁>>代碼示例>>Java>>正文


Java Consumer.handleDelivery方法代碼示例

本文整理匯總了Java中com.rabbitmq.client.Consumer.handleDelivery方法的典型用法代碼示例。如果您正苦於以下問題:Java Consumer.handleDelivery方法的具體用法?Java Consumer.handleDelivery怎麽用?Java Consumer.handleDelivery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.rabbitmq.client.Consumer的用法示例。


在下文中一共展示了Consumer.handleDelivery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testConsume

import com.rabbitmq.client.Consumer; //導入方法依賴的package包/類
@Test
public void testConsume() {
    HashSet<String> appIds = new HashSet<String>();
    appIds.addAll(Arrays.asList("app-1" ,"app-2", "app-3"));
    Envelope envelope = new Envelope(0L, false, "exchange-1", "test.app");

    AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
    builder.appId("app-1");
    builder.contentEncoding(CharEncoding.UTF_8);
    builder.contentType("application/json");

    AMQP.BasicProperties props = builder.build();

    ConsumeRMQChannel channel = new ConsumeRMQChannel("theQueue", appIds);
    channel.addRMQChannelListener(chListener);
    try {
        channel.open(connection);
        channel.consume();

        Consumer consumer = Mocks.consumerPool.pop();
        consumer.handleDelivery("consumerTag", envelope, props, "Test message".getBytes());

        assertEquals("Unmatched response size", 1, Mocks.responseArray.size());
        assertThat("Unmatch consumed queue.", Mocks.responseArray.get(0), is("listener-1"));
        channel.close();
    } catch (Exception ex) {
        fail(ex.toString());
    }
}
 
開發者ID:rinrinne,項目名稱:rabbitmq-consumer-plugin,代碼行數:30,代碼來源:ConsumeRMQChannelTest.java

示例2: testConsumereDelivery

import com.rabbitmq.client.Consumer; //導入方法依賴的package包/類
@Test
public void testConsumereDelivery() throws Exception
{
    final Channel channel       = mock(Channel.class);
    final FileSystem fs         = mock(FileSystem.class);
    final ShovelConfig cfg      = mock(ShovelConfig.class);
    final BufferedWriter w1     = mock(BufferedWriter.class);
    final BufferedWriter w2     = mock(BufferedWriter.class);
    final Shovel.Buffer b1      = new Shovel.Buffer(1L, "/tmp/1.tmp", "/tmp/1", w1);
    final Shovel.Buffer b2      = new Shovel.Buffer(2L, "/tmp/2.tmp", "/tmp/2", w2);
    final FSDataOutputStream os = mock(FSDataOutputStream.class);
    final Shovel instance       = new Shovel(channel, cfg){
        @Override
        protected FileSystem getFileSystem() throws IOException
        {
            return fs;
        }
    };

    final Consumer consumer                 = instance.createConsumer();
    final String consumerTag                = "fooTag";
    final Envelope envelope                 = mock(Envelope.class);
    final AMQP.BasicProperties properties   = mock(AMQP.BasicProperties.class);
    final byte[] body                       = "foo".getBytes();

    instance.buffers.put(1L, b1);
    instance.buffers.put(2L, b2);
    instance.tagReference.set(11L);

    when(cfg.getCurrentWindow()).thenReturn(33L);
    when(cfg.getGenerateUnique()).thenReturn("33");
    when(envelope.getDeliveryTag()).thenReturn(333L);
    when(cfg.getFileName("33")).thenReturn("/tmp/33");
    when(cfg.getTmpFileName("33")).thenReturn("/tmp/33.tmp");
    when(fs.create(new Path("/tmp/33.tmp"), true)).thenReturn(os);

    consumer.handleDelivery(consumerTag, envelope, properties, body);

    verify(cfg).getCurrentWindow();
    verify(cfg).getFileName("33");
    verify(cfg).getTmpFileName("33");
    verify(fs).create(new Path("/tmp/33.tmp"), true);

    assertEquals(3, instance.buffers.size());
    assertTrue(instance.buffers.containsKey(33L));
    assertEquals(333L, (long)instance.tagReference.get());
}
 
開發者ID:instaclick,項目名稱:amqp-to-hdfs-shovel,代碼行數:48,代碼來源:ShovelTest.java


注:本文中的com.rabbitmq.client.Consumer.handleDelivery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。