Search in sources :

Example 21 with Message

use of org.apache.rocketmq.common.message.Message in project paascloud-master by paascloud.

the class RocketMqProducer method sendSimpleMessage.

public static SendResult sendSimpleMessage(String body, String topic, String tag, String key, String pid, Integer delayLevel) {
    if (delayLevel == null) {
        delayLevel = 0;
    }
    Message message = MqMessage.checkMessage(body, topic, tag, key);
    if (delayLevel < 0 || delayLevel > GlobalConstant.Number.EIGHTEEN_INT) {
        throw new TpcBizException(ErrorCodeEnum.TPC100500013, topic, key);
    }
    message.setDelayTimeLevel(delayLevel);
    return retrySendMessage(pid, message);
}
Also used : Message(org.apache.rocketmq.common.message.Message) MqMessage(com.paascloud.core.mq.MqMessage) TpcBizException(com.paascloud.provider.exceptions.TpcBizException)

Example 22 with Message

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

the class LogProducer method send.

public void send(String text) throws Exception {
    Message msg = new // topic
    Message(// topic
    "Topic-DC-Output", // tag
    "TagB-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
    "KKK", // body 二进制字节数组
    text.getBytes());
    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)

Example 23 with Message

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

the class Producer method send.

// 每3s执行1次
@Scheduled(fixedDelay = 3000)
public void send() throws Exception {
    /*// send queue.
		
		MessageQueue mq = new MessageQueue("TEST", "brokerName", 1);
		Message msg = new Message("TEST", // topic
				"TEST", // tag
				"KKK", // key用于标识业务的唯一性
				"hi,RocketMQ".getBytes()// body 二进制字节数组
		);

		SendResult result = rocketmqTemplate.send(msg, mq);
		System.out.println(result);*/
    // send topic.
    Message msg2 = new // topic
    Message(// topic
    "Topic-DC-Output", // tag
    "TagA-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
    "KKK", // body 二进制字节数组
    (new Date() + ": hi,RocketMQ(topic) ").getBytes());
    SendResult result2 = rocketmqTemplate.send(msg2);
// System.out.println(result2);
}
Also used : Message(org.apache.rocketmq.common.message.Message) SendResult(org.apache.rocketmq.client.producer.SendResult) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 24 with Message

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

the class ProducerController method sendMsg.

/**
 * 顺序消息
 * @throws Exception
 */
@RequestMapping(value = "/sendMsg", method = RequestMethod.GET)
public void sendMsg() throws Exception {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            Message msg = new Message("order", "TagA", "OrderID11113", (i + ":" + j).getBytes());
            defaultProducer.send(msg, (List<MessageQueue> mqs, Message msg1, Object arg) -> {
                // TODO Auto-generated method stub
                int value = arg.hashCode();
                if (value < 0) {
                    value = Math.abs(value);
                }
                value = value % mqs.size();
                return mqs.get(value);
            }, i);
        }
    }
}
Also used : Message(org.apache.rocketmq.common.message.Message) List(java.util.List)

Example 25 with Message

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

the class ProducerController method rocketMq.

/**
 * 普通消息
 * @param tag
 * @param body
 * @param total
 * @return
 * @throws Exception
 */
@RequestMapping("/rocketMq/{tag}/{body}/{total}")
@ResponseBody
public String rocketMq(@PathVariable String tag, @PathVariable String body, @PathVariable Integer total) throws Exception {
    long t1 = System.currentTimeMillis();
    SendResult sendResult = null;
    int fail = 0;
    for (int i = 1; i < total + 1; i++) {
        Message msg = new // topic
        Message(// topic
        "test", // tag
        tag, // key
        "OrderID11112", // body
        (i + "").getBytes(RemotingHelper.DEFAULT_CHARSET));
        // 同步发送
        sendResult = defaultProducer.send(msg);
        if (sendResult.getSendStatus().name().equals(SendStatus.SEND_OK.name())) {
            fail++;
        } else {
            System.out.println(sendResult.getSendStatus().name());
        }
    }
    long t2 = System.currentTimeMillis();
    return "所花时间:" + (t2 - t1) + "成功次数" + fail;
}
Also used : Message(org.apache.rocketmq.common.message.Message)

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