当前位置: 首页>>代码示例>>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;未经允许,请勿转载。