Package com.taobao.metamorphosis.client.producer

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


        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        while ((line = readLine(reader)) != null) {
            // send message
            final SendResult sendResult = producer.sendMessage(new Message(topic, line.getBytes()));
            // 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


            case HttpStatus.Success: {
                // messageId partition offset
                final String[] tmps = RESULT_SPLITER.split(resultStr);
                // �ɹ���������Ϣid����Ϣid�ɷ���������
                MessageAccessor.setId(message, Long.parseLong(tmps[0]));
                return new SendResult(true, new Partition(0, Integer.parseInt(tmps[1])), Long.parseLong(tmps[2]), null);
            }
            case HttpStatus.Forbidden: {
                // �����������ر���,��д����
                return new SendResult(false, null, -1, String.valueOf(HttpStatus.Forbidden));
            }
            default:
                return new SendResult(false, null, -1, resultStr);
            }
        }
        catch (final Exception e) {
            this.logger.error(e.getMessage(), e);
            throw new MetaClientException(e);
View Full Code Here

                final Message msg = new Message(topic, data);
                final XAResource xares = messageProducer.getXAResource();
                final Xid xid =
                        XIDGenerator.createXID(this.formatIdIdGenerator.incrementAndGet(), this.UNIQUE_QUALIFIER);
                xares.start(xid, XAResource.TMNOFLAGS);
                final SendResult result = messageProducer.sendMessage(msg);
                if (!result.isSuccess() || i % 2 == 0) {
                    xares.end(xid, XAResource.TMFAIL);
                    xares.rollback(xid);
                }
                else {
                    xares.end(xid, XAResource.TMSUCCESS);
View Full Code Here

        // use template to send messages.
        final String topic = "meta-test";
        MetaqTemplate template = (MetaqTemplate) context.getBean("metaqTemplate");
        int count = 100;
        for (int i = 0; i < count; i++) {
            SendResult result =
                    template.send(MessageBuilder.withTopic(topic).withBody(new Trade(i, "test", i, "test")));
            assertTrue(result.isSuccess());
        }
        TradeMessageListener listener = (TradeMessageListener) context.getBean("messageListener");
        while (listener.counter.get() != count) {
            Thread.sleep(100);
        }
View Full Code Here

            final Xid xid = XIDGenerator.createXID(this.formatIdIdGenerator.incrementAndGet(), uniqueQualifier);
            // ��������ʱΪ2��
            xares.setTransactionTimeout(2);
            xares.start(xid, XAResource.TMNOFLAGS);

            final SendResult result = this.producer.sendMessage(msg);
            if (!result.isSuccess()) {
                xares.end(xid, XAResource.TMFAIL);
                xares.rollback(xid);
                throw new RuntimeException("Send message failed:" + result.getErrorMessage());
            }
            // �ȴ�3��
            xares.end(xid, XAResource.TMSUCCESS);
            Thread.sleep(3000);
            // prepare����ʧ��
            try {
                xares.prepare(xid);
                fail();
            }
            catch (final XAException e) {
                e.printStackTrace();
            }
            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

        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = null;
        while ((line = readLine(reader)) != null) {
            // send message
            final SendResult sendResult = producer.sendMessage(new Message(topic, line.getBytes()));
            // 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 sendMessage(final int count, final String strdata, final String topic) throws Exception {
        this.messages = new ArrayList<Message>();
        for (int i = 0; i < count; i++) {
            final byte[] data = (strdata + i).getBytes();
            final Message msg = new Message(topic, data);
            final SendResult result = this.producer.sendMessage(msg);
            if (!result.isSuccess()) {
                throw new RuntimeException("Send message failed:" + result.getErrorMessage());
            }
            System.out.println(i);
            this.messages.add(msg);
        }
    }
View Full Code Here

    public void sendMessage(final int count, final byte[] data, final String topic) throws Exception {
        this.messages = new ArrayList<Message>();
        for (int i = 0; i < count; i++) {
            final Message msg = new Message(topic, data);
            final SendResult result = this.producer.sendMessage(msg);
            if (!result.isSuccess()) {
                throw new RuntimeException("Send message failed:" + result.getErrorMessage());
            }
            this.messages.add(msg);
        }
    }
View Full Code Here

    public void sendMessage2(final int count, final String strdata, final String topic) throws Exception {
        this.messages = new ArrayList<Message>();
        for (int i = 0; i < count; i++) {
            final byte[] data = strdata.getBytes();
            final Message msg = new Message(topic, data);
            final SendResult result = this.producer.sendMessage(msg);
            if (!result.isSuccess()) {
                throw new RuntimeException("Send message failed:" + result.getErrorMessage());
            }
            this.messages.add(msg);
        }
    }
View Full Code Here

            // ��Ҫ����topic
            this.producerList.get(j).publish(topic);
            for (int i = 0; i < count; i++) {
                final byte[] data = ("hello" + j + i).getBytes();
                final Message msg = new Message(topic, 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

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.