Search in sources :

Example 26 with Message

use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.

the class RocketmqApplicationTests method contextLoads.

@Test
public void contextLoads() throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
    // Destination destination = new ActiveMQQueue("mytest.queue");
    Message msg = new // topic
    Message(// topic
    "TEST", // tag
    "TEST", // key用于标识业务的唯一性
    "KKK", // body 二进制字节数组
    "hi,RocketMQ".getBytes());
    for (int i = 0; i < 100; i++) {
        SendResult result = rocketmqTemplate.send(msg);
        System.out.println(result);
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 27 with Message

use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.

the class BroadcastProducer method main.

public static void main(String[] args) throws Exception {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();
    for (int i = 0; i < 100; i++) {
        Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
        SendResult sendResult = producer.send(msg);
        System.out.printf("%s%n", sendResult);
    }
    producer.shutdown();
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer)

Example 28 with Message

use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.

the class ListSplitter method next.

@Override
public List<Message> next() {
    int nextIndex = currIndex;
    int totalSize = 0;
    for (; nextIndex < messages.size(); nextIndex++) {
        Message message = messages.get(nextIndex);
        int tmpSize = message.getTopic().length() + message.getBody().length;
        Map<String, String> properties = message.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            tmpSize += entry.getKey().length() + entry.getValue().length();
        }
        // for log overhead
        tmpSize = tmpSize + 20;
        if (tmpSize > SIZE_LIMIT) {
            // here just let it go, otherwise it will block the splitting process
            if (nextIndex - currIndex == 0) {
                // if the next sublist has no element, add this one and then break, otherwise just break
                nextIndex++;
            }
            break;
        }
        if (tmpSize + totalSize > SIZE_LIMIT) {
            break;
        } else {
            totalSize += tmpSize;
        }
    }
    List<Message> subList = messages.subList(currIndex, nextIndex);
    currIndex = nextIndex;
    return subList;
}
Also used : Message(org.apache.rocketmq.common.message.Message) Map(java.util.Map)

Example 29 with Message

use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.

the class OrderedProducer method main.

public static void main(String[] args) throws Exception {
    // Instantiate with a producer group name.
    MQProducer producer = new DefaultMQProducer("example_group_name");
    // Launch the instance.
    producer.start();
    String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
    for (int i = 0; i < 100; i++) {
        int orderId = i % 10;
        // Create a message instance, specifying topic, tag and message body.
        Message msg = new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
        SendResult sendResult = producer.send(msg, new MessageQueueSelector() {

            @Override
            public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
                Integer id = (Integer) arg;
                int index = id % mqs.size();
                return mqs.get(index);
            }
        }, orderId);
        System.out.printf("%s%n", sendResult);
    }
    // server shutdown
    producer.shutdown();
}
Also used : Message(org.apache.rocketmq.common.message.Message) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MQProducer(org.apache.rocketmq.client.producer.MQProducer) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) MessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SendResult(org.apache.rocketmq.client.producer.SendResult)

Aggregations

Message (org.apache.rocketmq.common.message.Message)29 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)13 SendResult (org.apache.rocketmq.client.producer.SendResult)12 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Channel (org.apache.flume.Channel)2 Event (org.apache.flume.Event)2 EventDeliveryException (org.apache.flume.EventDeliveryException)2 Transaction (org.apache.flume.Transaction)2 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2 SendCallback (org.apache.rocketmq.client.producer.SendCallback)2 MessageExt (org.apache.rocketmq.common.message.MessageExt)2 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)2 Test (org.junit.Test)2 BusinessException (com.paascloud.base.exception.BusinessException)1 MqMessage (com.paascloud.core.mq.MqMessage)1 TpcBizException (com.paascloud.provider.exceptions.TpcBizException)1 List (java.util.List)1