Package com.taobao.metamorphosis

Examples of com.taobao.metamorphosis.Message


                        if (pstmt.executeUpdate() <= 0) {
                            status.setRollbackOnly();
                            return null;
                        }
                        pstmt.close();
                        if (!producer.sendMessage(new Message(topic, address.getBytes())).isSuccess()) {
                            status.setRollbackOnly();
                        }
                        return null;
                    }
                });
View Full Code Here


    }


    private Message createDefaultMessage(final String topic) {
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        return message;
    }
View Full Code Here

        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

        this.brokerZooKeeper.unregisterEveryThing();
        EasyMock.expectLastCall();
        final long msgId = 100000L;
        EasyMock.expect(this.idWorker.nextId()).andReturn(msgId);
        final String testTopic = Constants.TEST_SLAVE_TOPIC;
        Message msg = new Message(testTopic, "test".getBytes());
        // ����slave
        byte[] encodePayload = MessageUtils.encodePayload(msg);
        int flag = 0;
        int partition = 0;
        // skip two messages.
View Full Code Here

        }
        catch (final InvalidMessageException e) {
            assertEquals("Null message", e.getMessage());
        }
        try {
            this.producer.sendMessage(new Message(null, "hello".getBytes()));
            fail();
        }
        catch (final InvalidMessageException e) {
            assertEquals("Blank topic", e.getMessage());
        }
        try {
            this.producer.sendMessage(new Message("topic", null));
            fail();
        }
        catch (final InvalidMessageException e) {
            assertEquals("Null data", e.getMessage());
        }
View Full Code Here

    @Test
    public void testSendMessageNormal_NoPartitions() throws Exception {
        final String topic = "topic1";
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector)).andReturn(null);
        this.mocksControl.replay();
        try {
            this.producer.sendMessage(message);
            fail();
View Full Code Here

    @Test
    public void testSendMessageNormal_NoBroker() throws Exception {
        final String topic = "topic1";
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        final Partition partition = new Partition("0-0");
        EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector)).andReturn(
            partition);
        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(null);
        this.mocksControl.replay();
        try {
            this.producer.sendMessage(new Message(topic, data));
            fail();
        }
        catch (final MetaClientException e) {
            // e.printStackTrace();
        }
View Full Code Here

    @Test
    public void testSendOrderedMessageServerError() throws Exception {
        final String topic = "topic1";
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        final String url = "meta://localhost:0";
        final Partition partition = new Partition("0-0");
        // �����ظ�3��
        EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector)).andReturn(
            partition);// .times(3);
        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);// .times(3);
        OpaqueGenerator.resetOpaque();
        final int flag = MessageFlagUtils.getFlag(null);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url,
                new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data), null,
                    Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                        new BooleanCommand(500, "server error", Integer.MIN_VALUE));
        // EasyMock.expect(
        // this.remotingClient.invokeToGroup(url, new PutCommand(topic,
        // partition.getPartition(), data, null, flag,
        // Integer.MIN_VALUE + 1), 3000, TimeUnit.MILLISECONDS)).andReturn(
        // new BooleanCommand(Integer.MIN_VALUE, 500, "server error"));
        // EasyMock.expect(
        // this.remotingClient.invokeToGroup(url, new PutCommand(topic,
        // partition.getPartition(), data, null, flag,
        // Integer.MIN_VALUE + 2), 3000, TimeUnit.MILLISECONDS)).andReturn(
        // new BooleanCommand(Integer.MIN_VALUE, 500, "server error"));
        this.mocksControl.replay();
        assertEquals(0, message.getId());
        final SendResult sendResult = this.producer.sendMessage(message);

        this.mocksControl.verify();
        assertFalse(sendResult.isSuccess());
        assertEquals(-1, sendResult.getOffset());
View Full Code Here

    public void testSendMessageInterrupted() throws Exception {
        boolean interrupted = false;
        try {
            final String topic = "topic1";
            final byte[] data = "hello".getBytes();
            final Message message = new Message(topic, data);
            final String url = "meta://localhost:0";
            final Partition partition = new Partition("0-0");
            EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector)).andReturn(
                partition);
            EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
View Full Code Here

    @Test
    public void testEncodeData_NoAttribute() {
        final String topic = "topic1";
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        final byte[] encoded = MessageUtils.encodePayload(message);
        assertEquals("hello", new String(encoded));
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.Message

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.