Package com.taobao.metamorphosis.client.producer

Examples of com.taobao.metamorphosis.client.producer.SendResult


            messageProducer.publish(topic);
            for (int i = 0; i < count; i++) {
                final byte[] data = ("hello" + j + i).getBytes();
                final Message msg = new Message(topic, data);
                messageProducer.beginTransaction();
                final SendResult result = messageProducer.sendMessage(msg);
                if (!result.isSuccess()) {
                    messageProducer.rollback();
                    throw new RuntimeException("Send message failed:" + result.getErrorMessage());
                }
                messageProducer.commit();
                this.messages.add(msg);
            }
        }
View Full Code Here


                    msg = new Message(topic1, data, attributed1);
                }
                else {
                    msg = new Message(topic1, data);
                }
                final SendResult result = this.producerList.get(j).sendMessage(msg);
                if (!result.isSuccess()) {
                    throw new RuntimeException("Send message failed:" + result.getErrorMessage());
                }
                this.messages.add(msg);
            }
        }
        for (int j = 0; j < num; j++) {
            // ��Ҫ����topic
            this.producerList.get(j).publish(topic2);
            for (int i = 0; i < count; i++) {
                final byte[] data = ("hello" + i + j).getBytes();
                final Message msg;
                if (attributed == true) {
                    msg = new Message(topic1, data, attributed2);
                }
                else {
                    msg = new Message(topic1, data);
                }
                final SendResult result = this.producerList.get(j).sendMessage(msg);
                if (!result.isSuccess()) {
                    throw new RuntimeException("Send message failed:" + result.getErrorMessage());
                }
                this.messages.add(msg);
            }
        }
    }
View Full Code Here

    @Test
    public void testSendMessage() throws MetaClientException {
        final SimpleHttpProducer client = new SimpleHttpProducer(new HttpClientConfig("localhost", 8080));
        final Message message = new Message("meta-test", "world".getBytes());
        message.setAttribute(System.currentTimeMillis() + "");
        final SendResult result = client.sendMessage(message, new Partition(1, 1));
        logger.info("send message:" + result.isSuccess());
    }
View Full Code Here

        String line = null;
        long tradeId = 0;
        int money = 1000;
        while ((line = readLine(reader)) != null) {
            // send message
            final SendResult sendResult =
                    template.send(MessageBuilder.withTopic(topic).withBody(new Trade(tradeId++, line, money++, line)));
            // check result
            if (!sendResult.isSuccess()) {
                System.err.println("Send message failed,error message:" + sendResult.getErrorMessage());
            }
            else {
                System.out.println("Send message successfully,sent to " + sendResult.getPartition());
            }
        }
    }
View Full Code Here

    public void testSendMsg() throws Exception {
        EasyMock.expect(this.sessionFactory.createProducer()).andReturn(this.producer);
        this.producer.publish("test");
        EasyMock.expectLastCall();
        MessageBuilder builder = MessageBuilder.withTopic("test").withBody("hello world");
        SendResult rt = new SendResult(true, null, 0, null);
        EasyMock.expect(this.producer.sendMessage(builder.build(this.messageBodyConverter))).andReturn(rt);

        this.control.replay();
        assertSame(rt, this.tempalte.send(builder));
        this.control.verify();
View Full Code Here

    public void testSendMsgTwice() throws Exception {
        EasyMock.expect(this.sessionFactory.createProducer()).andReturn(this.producer);
        this.producer.publish("test");
        EasyMock.expectLastCall();
        MessageBuilder builder = MessageBuilder.withTopic("test").withBody("hello world");
        SendResult rt = new SendResult(true, null, 0, null);
        EasyMock.expect(this.producer.sendMessage(builder.build(this.messageBodyConverter))).andReturn(rt).times(2);

        this.control.replay();
        assertSame(rt, this.tempalte.send(builder));
        assertSame(rt, this.tempalte.send(builder));
View Full Code Here

    public void testSendMsgThrowException() throws Exception {
        EasyMock.expect(this.sessionFactory.createProducer()).andReturn(this.producer);
        this.producer.publish("test");
        EasyMock.expectLastCall();
        MessageBuilder builder = MessageBuilder.withTopic("test").withBody("hello world");
        SendResult rt = new SendResult(false, null, -1, "test");
        EasyMock.expect(this.producer.sendMessage(builder.build(this.messageBodyConverter))).andThrow(
            new MetaClientException("test"));

        this.control.replay();
        SendResult sent = this.tempalte.send(builder);
        assertFalse(sent.isSuccess());
        assertNotNull(sent.getErrorMessage());
        assertEquals(-1, sent.getOffset());
        assertNull(sent.getPartition());
        this.control.verify();
    }
View Full Code Here

            this.remotingClient.invokeToGroup(url, new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data),
                null, Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                    new BooleanCommand(200, "1111 1 1024", Integer.MIN_VALUE));
        this.mocksControl.replay();
        assertEquals(0, message.getId());
        final SendResult sendResult = this.producer.sendMessage(message);

        this.mocksControl.verify();
        assertTrue(sendResult.isSuccess());
        assertEquals(1024, sendResult.getOffset());
        assertEquals(1, sendResult.getPartition().getPartition());
        assertEquals(0, sendResult.getPartition().getBrokerId());
        assertEquals(1111, message.getId());
    }
View Full Code Here

    public void testSendMsgWithCallback() throws Exception {
        EasyMock.expect(this.sessionFactory.createProducer()).andReturn(this.producer);
        this.producer.publish("test");
        EasyMock.expectLastCall();
        MessageBuilder builder = MessageBuilder.withTopic("test").withBody("hello world");
        final SendResult rt = new SendResult(true, null, 0, null);
        SendMessageCallback cb = new SendMessageCallback() {

            @Override
            public void onMessageSent(SendResult result) {
                assertSame(rt, result);
View Full Code Here

    SendResult saveMessageToLocal(final Message message, final Partition partition, final long timeout,
            final TimeUnit unit) {
        try {
            this.localMessageStorageManager.append(message, partition);
            return new SendResult(true, partition, -1, "send to local");
        }
        catch (final IOException e) {
            log.error("send message to local failed,topic=" + message.getTopic() + ",content["
                    + HexSupport.toHexFromBytes(message.getData()) + "]");
            return new SendResult(false, null, -1, "send message to local failed");
        }
    }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.client.producer.SendResult

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.