Package com.taobao.metamorphosis

Examples of com.taobao.metamorphosis.Message


    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);
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

        for (int j = 0; j < num; j++) {
            // ��Ҫ����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

            // ��Ҫ����topic
            final MessageProducer messageProducer = this.producerList.get(j);
            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());
View Full Code Here

        for (int j = 0; j < num; j++) {
            // ��Ҫ����topic
            this.producerList.get(j).publish(topic1);
            for (int i = 0; i < count; i++) {
                final byte[] data = ("hello" + j + i).getBytes();
                final Message msg;
                if (attributed == true) {
                    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());
                }
View Full Code Here

            public void run() {
                boolean slaveOk = false;
                while (!slaveOk && !Thread.currentThread().isInterrupted()) {
                    try {
                        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;
                        SyncCommand command =
View Full Code Here

        MessageIterator it = null;
        // get messages
        long syncOffSet = this.offset;
        while ((it = client.get("meta-test", new Partition(1, 1), syncOffSet, 99999)) != null) {
            while (it.hasNext()) {
                final Message msg = it.next();
                logger.info("Receive message:" + new String(msg.getData()));
                logger.info("message attribute:" + msg.getAttribute());
            }

            syncOffSet += it.getOffset();
        }
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

    public void testOnReceiveMessagesWithConverter() throws Exception {
        MyMessageListener listener = new MyMessageListener();
        JavaSerializationMessageBodyConverter messageBodyConverter = new JavaSerializationMessageBodyConverter();
        listener.setMessageBodyConverter(messageBodyConverter);
        listener.afterPropertiesSet();
        Message message = new Message("test", messageBodyConverter.toByteArray("hello world"));
        listener.recieveMessages(message);

        assertNotNull(listener.recvMsg);
        assertEquals("hello world", listener.recvMsg.getBody());
        assertSame(message, listener.recvMsg.getRawMessage());
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.