com.alibaba.rocketmq.client.producer.SendResult Java Examples

The following examples show how to use com.alibaba.rocketmq.client.producer.SendResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Producer.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();

    try {
        for (int i = 0; i < 6000000; i++) {
            Message msg = new Message("TopicFilter7",// topic
                    "TagA",// tag
                    "OrderID001",// key
                    ("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body

            msg.putUserProperty("SequenceId", String.valueOf(i));

            SendResult sendResult = producer.send(msg);
            System.out.println(sendResult);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    producer.shutdown();
}
 
Example #2
Source File: RocketMQSender.java    From easyooo-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean send(Message data) throws Exception {
	if(data == null){
		return false;
	}
	try{
		SendResult sr = producer.send(data);
		if(sr.getSendStatus() != SendStatus.SEND_OK){
			logger.warn(String.format("Message(%s) has been sent successfully, but send status is %s.", 
					data.getTopic(), sr.getSendStatus()));
		}
	}catch(Exception e){
		if(needFaultTolerant){
			putInErrorQueue(data);
		}
		throw e;
	}
	return true;
}
 
Example #3
Source File: Producer.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();

    try {
        for (int i = 0; i < 6000000; i++) {
            Message msg = new Message("TopicFilter7", // topic
                "TagA", // tag
                "OrderID001", // key
                ("Hello MetaQ").getBytes());// body

            msg.putUserProperty("SequenceId", String.valueOf(i));

            SendResult sendResult = producer.send(msg);
            System.out.println(sendResult);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    producer.shutdown();
}
 
Example #4
Source File: Producer.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name");

    producer.start();

    for (int i = 0; i < 1000; i++) {
        try {
            Message msg = new Message("TopicTest", // topic
                "TagA", // tag
                ("Hello RocketMQ " + i).getBytes()// body
            );
            SendResult sendResult = producer.send(msg);
            System.out.println(sendResult);
        }
        catch (Exception e) {
            e.printStackTrace();
            Thread.sleep(1000);
        }
    }

    producer.shutdown();
}
 
Example #5
Source File: Producer.java    From zheng with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    DefaultMQProducer producer = new DefaultMQProducer("Producer");
    producer.setNamesrvAddr("127.0.0.1:9876");
    try {
        producer.start();
        long time = System.currentTimeMillis();
        System.out.println("开始:" + time);

        int a = 100000;

        for (int i = 1; i <= a; i++) {
            Message msg = new Message("PushTopic", "push", i + "", "Just for test.".getBytes());
            SendResult result = producer.send(msg);
            System.out.println("id:" + result.getMsgId() + " result:" + result.getSendStatus());
        }
        System.out.println("结束,消耗:" + (System.currentTimeMillis() - time));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        producer.shutdown();
    }
}
 
Example #6
Source File: SendMsgStatusCommand.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC",rpcHook);
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;

        producer.send(buildMessage(brokerName, 16));

        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.println("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        producer.shutdown();
    }
}
 
Example #7
Source File: Producer.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {

        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");

        producer.start();

        for (int i = 0; i < 10000000; i++)
            try {
                {
                    Message msg = new Message("TopicTest",// topic
                            "TagA",// tag
                            "OrderID188",// key
                            ("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body
                    SendResult sendResult = producer.send(msg);
                    System.out.println(sendResult);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        producer.shutdown();
    }
 
Example #8
Source File: SendMsgStatusCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC");
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('s')) : 20;
        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.println("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        producer.shutdown();
    }
}
 
Example #9
Source File: Producer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();

    try {
        for (int i = 0; i < 6000000; i++) {
            Message msg = new Message("TopicFilter7",// topic
                "TagA",// tag
                "OrderID001",// key
                ("Hello MetaQ").getBytes());// body

            msg.putUserProperty("SequenceId", String.valueOf(i));

            SendResult sendResult = producer.send(msg);
            System.out.println(sendResult);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    producer.shutdown();
}
 
Example #10
Source File: Producer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
        DefaultMQProducer producer = new DefaultMQProducer("yyzGroup2");
        producer.setNamesrvAddr("10.2.223.157:9876;10.2.223.158:9876;10.2.223.159:9876");
       // producer.setNamesrvAddr("10.2.223.228:9876");
        producer.start();
        for(int i = 0; i < 111111; ++i) {
//            Thread.currentThread().sleep(50);
//            for (String item : array) {
            Message msg = new Message("yyztest2",// topic
                    "TAG",// tag
                    "ffff",// 注意, msgkey对帮助业务排查消息投递问题很有帮助,请设置成和消息有关的业务属性,比如订单id ,商品id .
                    "yang ya zhou".getBytes());// body //默认会设置等待消息存储成功。
            SendResult sendResult = null;
            try {//同步发送消息 ,并且等待消息存储成功,超时时间3s .
                System.out.println("send msg with msgKey:" + msg.getKeys());
                sendResult = producer.send(msg); //DefaultMQProducer.send
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(sendResult);
            Thread.sleep(300);
        }
        System.out.println(System.getProperty("user.home") );
        producer.shutdown();
    }
 
Example #11
Source File: TestProducer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();
    for (int i = 0; i < 1; i++)
        try {
            {
                Message msg = new Message("TopicTest1",// topic
                    "TagA",// tag
                    "key113",// key
                    ("Hello MetaQ").getBytes());// body
                SendResult sendResult = producer.send(msg);
                System.out.println(sendResult);

                QueryResult queryMessage =
                        producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis());
                for (MessageExt m : queryMessage.getMessageList()) {
                    System.out.println(m);
                }
            }

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    producer.shutdown();
}
 
Example #12
Source File: Producer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(//
                    topic,// topic
                    tags,// tag
                    keys,// key
                    ("Hello RocketMQ " + i).getBytes());// body
                SendResult sendResult = producer.send(msg);

                System.out.printf("%-8d %s\n", i, sendResult);
            }
            catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}
 
Example #13
Source File: RocketMQProducerService.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public SendResult sendBytesMessage(String topic, String tags, byte[] body, Consumer<Throwable> errorHandler){
	Message message = new Message();
	message.setTopic(topic);
	message.setTags(tags);
	message.setBody(body);
	return sendRawMessage(message, errorHandler);
}
 
Example #14
Source File: RocketMqTracingCollector.java    From dubbo-plus with Apache License 2.0 5 votes vote down vote up
@Override
public void push(List<Span> spanList) {
    byte[] bytes = JSON.toJSONBytes(spanList);
    Message message = new Message(DstConstants.ROCKET_MQ_TOPIC,bytes);
    try {
        SendResult sendResult = defaultMQProducer.send(message);
        if(sendResult.getSendStatus()!= SendStatus.SEND_OK){
            logger.error("send mq message return ["+sendResult.getSendStatus()+"]");
        }
    } catch (Exception e) {
        logger.error("fail to send message.",e);
    }
}
 
Example #15
Source File: MQClientAPIImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public SendResult sendMessage(//
        final String addr,// 1
        final String brokerName,// 2
        final Message msg,// 3
        final SendMessageRequestHeader requestHeader,// 4
        final long timeoutMillis,// 5
        final CommunicationMode communicationMode,// 6
        final SendCallback sendCallback// 7
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand request = null;
    if (sendSmartMsg) {
        SendMessageRequestHeaderV2 requestHeaderV2 = SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    }
    else { //组装头部信息
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody()); //包体body信息赋值

    switch (communicationMode) {
    case ONEWAY:
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
        return null;
    case ASYNC:
        this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
        return null;
    case SYNC:
        return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
    default:
        assert false;
        break;
    }

    return null;
}
 
Example #16
Source File: MqProducerController.java    From RocketMqCurrencyBoot with Apache License 2.0 5 votes vote down vote up
/**
 *    添加一个消息到MQ 
 *      使用该方法 请注意  Topic  Tags  参数     
 *      
 * @param Topic   队列名称
 * @param Tags	     标签名称  
 * @param body    实际数据
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<List<String>> controllerMq(@RequestParam("Topic") String Topic,
		@RequestParam("Tags") String Tags, @RequestParam("body") String body)
{
	List<String> list = new ArrayList<String>();
	try
	{
		String getRequestData = "接收到的消息是   Topic=" + Topic + " Tags= " + Tags + " body= "
				+ body;

		LOGGER.debug(getRequestData);

		SendResult sendResult = mqProducer.send(Topic, Tags, body);
		LOGGER.debug("响应的数据是:" + sendResult);
		if (null != sendResult)
		{
			list.add("SendStatus = " + sendResult.getSendStatus() + " msgId ="
					+ sendResult.getMsgId());
			return ResponseEntity.ok(list);
		}
		list.add(" 添加到MQ 失败 !");
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(list);
	}
	catch (UnsupportedEncodingException e)
	{
		LOGGER.error("MqProducerController 发送异常", e);
		list.add(e.getMessage());
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(list);
	}
}
 
Example #17
Source File: MQClientAPIImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private SendResult sendMessageSync(//
        final String addr,//
        final String brokerName,//
        final Message msg,//
        final long timeoutMillis,//
        final RemotingCommand request//
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
    assert response != null;
    return this.processSendResponse(brokerName, msg, response);
}
 
Example #18
Source File: TestProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {

        DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");

        producer.start();

        for (int i = 0; i < 1; i++)
            try {
                {
                    Message msg = new Message("TopicTest1",// topic
                            "TagA",// tag
                            "key113",// key
                            ("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body
                    SendResult sendResult = producer.send(msg);
                    System.out.println(sendResult);

                    QueryResult queryMessage =
                            producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis());
                    for (MessageExt m : queryMessage.getMessageList()) {
                        System.out.println(m);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        producer.shutdown();
    }
 
Example #19
Source File: Producer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(//
                        topic,// topic
                        tags,// tag
                        keys,// key
                        ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));// body
                SendResult sendResult = producer.send(msg);

                System.out.printf("%-8d %s%n", i, sendResult);
            } catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}
 
Example #20
Source File: TransactionProducer.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {

        TransactionCheckListener transactionCheckListener = new TransactionCheckListenerImpl();
        TransactionMQProducer producer = new TransactionMQProducer("please_rename_unique_group_name");
        // 事务回查最小并发数
        producer.setCheckThreadPoolMinSize(2);
        // 事务回查最大并发数
        producer.setCheckThreadPoolMaxSize(2);
        // 队列数
        producer.setCheckRequestHoldMax(2000);
        producer.setTransactionCheckListener(transactionCheckListener);
        producer.start();

        String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
        TransactionExecuterImpl tranExecuter = new TransactionExecuterImpl();
        for (int i = 0; i < 100; i++) {
            try {
                Message msg = new Message("TopicTest", tags[i % tags.length], "KEY" + i,
                    ("Hello RocketMQ " + i).getBytes());
                SendResult sendResult = producer.sendMessageInTransaction(msg, tranExecuter, null);
                System.out.println(sendResult);

                Thread.sleep(10);
            }
            catch (MQClientException e) {
                e.printStackTrace();
            }
        }

        for (int i = 0; i < 100000; i++) {
            Thread.sleep(1000);
        }

        producer.shutdown();

    }
 
Example #21
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private SendResult sendMessageSync(//
                                   final String addr, //
                                   final String brokerName, //
                                   final Message msg, //
                                   final long timeoutMillis, //
                                   final RemotingCommand request//
) throws RemotingException, MQBrokerException, InterruptedException {
    RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
    assert response != null;
    return this.processSendResponse(brokerName, msg, response);
}
 
Example #22
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public SendResult sendMessage(//
                              final String addr, // 1
                              final String brokerName, // 2
                              final Message msg, // 3
                              final SendMessageRequestHeader requestHeader, // 4
                              final long timeoutMillis, // 5
                              final CommunicationMode communicationMode, // 6
                              final SendMessageContext context, // 7
                              final DefaultMQProducerImpl producer // 8
) throws RemotingException, MQBrokerException, InterruptedException {
    return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer);
}
 
Example #23
Source File: TransactionProducer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {

        //事务决断处理类
        TransactionCheckListener transactionCheckListener = new TransactionCheckListenerImpl();
        TransactionMQProducer producer = new TransactionMQProducer("please_rename_unique_group_name");
        producer.setCheckThreadPoolMinSize(2);
        producer.setCheckThreadPoolMaxSize(2);
        producer.setCheckRequestHoldMax(2000);
        producer.setTransactionCheckListener(transactionCheckListener);
        producer.start();

        String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
        TransactionExecuterImpl tranExecuter = new TransactionExecuterImpl();
        for (int i = 0; i < 100; i++) {
            try {
                Message msg =
                        new Message("TopicTest", tags[i % tags.length], "KEY" + i,
                            ("Hello RocketMQ " + i).getBytes());
                SendResult sendResult = producer.sendMessageInTransaction(msg, tranExecuter, null);
                System.out.println(sendResult);

                Thread.sleep(10);
            }
            catch (MQClientException e) {
                e.printStackTrace();
            }
        }

        for (int i = 0; i < 100000; i++) {
            Thread.sleep(1000);
        }

        producer.shutdown();

    }
 
Example #24
Source File: OnSuccessInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
    if (sendStatus != SendStatus.SEND_OK) {
        activeSpan.errorOccurred();
        Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
    }
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
 
Example #25
Source File: Producer.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws MQClientException, InterruptedException {
    CommandLine commandLine = buildCommandline(args);
    if (commandLine != null) {
        String group = commandLine.getOptionValue('g');
        String topic = commandLine.getOptionValue('t');
        String tags = commandLine.getOptionValue('a');
        String keys = commandLine.getOptionValue('k');
        String msgCount = commandLine.getOptionValue('c');

        DefaultMQProducer producer = new DefaultMQProducer(group);
        producer.setInstanceName(Long.toString(System.currentTimeMillis()));

        producer.start();

        for (int i = 0; i < Integer.parseInt(msgCount); i++) {
            try {
                Message msg = new Message(//
                    topic, // topic
                    tags, // tag
                    keys, // key
                    ("Hello RocketMQ " + i).getBytes());// body
                SendResult sendResult = producer.send(msg);

                System.out.printf("%-8d %s\n", i, sendResult);
            }
            catch (Exception e) {
                e.printStackTrace();
                Thread.sleep(1000);
            }
        }

        producer.shutdown();
    }
}
 
Example #26
Source File: MQClientAPIImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
/**
 * 发送消息 通用方法
 * 
 * @param addr
 *            目标broker ip
 * @param brokerName
 * @param msg
 * @param requestHeader
 * @param timeoutMillis
 * @param communicationMode
 *            发送消息的发送 :同步,异步,单向
 * @param sendCallback
 * @return
 * @throws RemotingException
 * @throws MQBrokerException
 * @throws InterruptedException
 */
public SendResult sendMessage(final String addr, final String brokerName, final Message msg,
        final SendMessageRequestHeader requestHeader, final long timeoutMillis,
        final CommunicationMode communicationMode, final SendCallback sendCallback)
                throws RemotingException, MQBrokerException, InterruptedException {
    if (!UtilAll.isBlank(projectGroupPrefix)) {
        msg.setTopic(VirtualEnvUtil.buildWithProjectGroup(msg.getTopic(), projectGroupPrefix));
        requestHeader.setProducerGroup(
            VirtualEnvUtil.buildWithProjectGroup(requestHeader.getProducerGroup(), projectGroupPrefix));
        requestHeader
            .setTopic(VirtualEnvUtil.buildWithProjectGroup(requestHeader.getTopic(), projectGroupPrefix));
    }

    RemotingCommand request = null;
    if (sendSmartMsg) {
        SendMessageRequestHeaderV2 requestHeaderV2 =
                SendMessageRequestHeaderV2.createSendMessageRequestHeaderV2(requestHeader);
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE_V2, requestHeaderV2);
    }
    else {
        request = RemotingCommand.createRequestCommand(RequestCode.SEND_MESSAGE, requestHeader);
    }

    request.setBody(msg.getBody());

    switch (communicationMode) {
    case ONEWAY:
        this.remotingClient.invokeOneway(addr, request, timeoutMillis);
        return null;
    case ASYNC:
        this.sendMessageAsync(addr, brokerName, msg, timeoutMillis, request, sendCallback);
        return null;
    case SYNC:
        return this.sendMessageSync(addr, brokerName, msg, timeoutMillis, request);
    default:
        assert false;
        break;
    }

    return null;
}
 
Example #27
Source File: CheckForbiddenContext.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public SendResult getSendResult() {
    return sendResult;
}
 
Example #28
Source File: CheckForbiddenContext.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public void setSendResult(SendResult sendResult) {
    this.sendResult = sendResult;
}
 
Example #29
Source File: CheckForbiddenContext.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public void setSendResult(SendResult sendResult) {
    this.sendResult = sendResult;
}
 
Example #30
Source File: SendMessageContext.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public SendResult getSendResult() {
    return sendResult;
}