Package com.taobao.metamorphosis.consumer

Examples of com.taobao.metamorphosis.consumer.MessageIterator


        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                throw new RuntimeException("A stupid bug");
View Full Code Here


        final FetchRequest request =
                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();

        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, data));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                System.out.println("Rollback current message");
View Full Code Here

                new FetchRequest(broker, 0, new TopicPartitionRegInfo(topic, partition, offset), maxSize);
        // ��������������0��
        request.incrementRetriesAndGet();

        final FetchRequestRunner runner = this.fetchManager.new FetchRequestRunner();
        EasyMock.expect(this.consumer.fetch(request, -1, null)).andReturn(new MessageIterator(topic, new byte[10]));
        EasyMock.expect(this.consumer.getMessageListener(topic)).andReturn(new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                fail();
View Full Code Here

                            ByteBuffer.allocate(Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
                    set.read(byteBuffer);
                    byte[] bytes = this.getBytesFromBuffer(byteBuffer);
                    // If filter is not null,we filter the messages by it.
                    if (filter != null) {
                        MessageIterator it = new MessageIterator(topic, bytes);
                        // reuse the buffer.
                        byteBuffer.clear();
                        while (it.hasNext()) {
                            Message msg = it.next();
                            try {
                                if (filter.accept(group, msg)) {
                                    ByteBuffer msgBuf = it.getCurrentMsgBuf();
                                    // Append current message buffer to result
                                    // buffer.
                                    byteBuffer.put(msgBuf);
                                }
                            }
                            catch (Exception e) {
                                log.error("Filter message for consumer failed,topic=" + topic + ",group=" + group
                                    + ",filterClass=" + filter.getClass().getCanonicalName(), e);
                            }
                        }
                        // re-new the byte array.
                        bytes = this.getBytesFromBuffer(byteBuffer);
                        // All these messages are not acceptable,move forward
                        // offset.
                        if (bytes.length == 0) {
                            return new BooleanCommand(HttpStatus.Moved, String.valueOf(request.getOffset()
                                + it.getOffset()), request.getOpaque());
                        }
                    }
                    return new DataCommand(bytes, request.getOpaque(), true);
                }
            }
View Full Code Here

        final String group = "meta-example";
        // create consumer,ǿ�ҽ���ʹ�õ���
        final MessageConsumer consumer = sessionFactory.createConsumer(new ConsumerConfig(group));
        // start offset
        long offset = 0;
        MessageIterator it = null;
        // fetch messages
        while ((it = consumer.get(topic, new Partition("100-0"), offset, 1024 * 1024)) != null) {
            while (it.hasNext()) {
                final Message msg = it.next();
                System.out.println("Receive message " + new String(msg.getData()));
            }
            // move offset forward
            offset += it.getOffset();
        }

    }
View Full Code Here

        final int maxSize = 1024;
        final Partition partition = new Partition("0-0");
        final long offset = 12;
        final byte[] data = "hello".getBytes();
        final String url = "meta://localhost:0";
        final MessageIterator messageIterator = new MessageIterator(topic, data);

        this.producerZooKeeper.publishTopic(topic, this.consumer);
        EasyMock.expect(this.remotingClient.isConnected(url)).andReturn(true);
        EasyMock.expectLastCall();
        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
View Full Code Here

        final int maxSize = 1024;
        final Partition partition = new Partition("0-0");
        final long offset = 12;
        final byte[] data = "hello".getBytes();
        final String url = "meta://localhost:0";
        final MessageIterator messageIterator = new MessageIterator(topic, data);

        this.producerZooKeeper.publishTopic(topic, this.consumer);
        EasyMock.expectLastCall();
        EasyMock.expect(this.remotingClient.isConnected(url)).andReturn(true);
        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
View Full Code Here

            }
            this.createConsumer("consumer-test");
            // this.consumer.subscribe(this.topic, 1024,
            // null).completeSubscribe();
            System.out.println(result.getPartition());
            final MessageIterator it = this.consumer.get(this.topic, result.getPartition(), 0, 1024);
            assertNull(it);
        }
        finally {
            this.producer.shutdown();
            this.consumer.shutdown();
View Full Code Here

    private MessageIterator it;


    @Test
    public void testHasNext_NullData() {
        this.it = new MessageIterator("test", null);
        assertFalse(this.it.hasNext());

    }
View Full Code Here

    }


    @Test
    public void testHasNext_EmptyData() {
        this.it = new MessageIterator("test", new byte[0]);
        assertFalse(this.it.hasNext());

    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.consumer.MessageIterator

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.