Java Code Examples for com.alibaba.rocketmq.common.message.Message#setTopic()

The following examples show how to use com.alibaba.rocketmq.common.message.Message#setTopic() . 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 reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private static Message buildMessage(final int messageSize) {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes());

    return msg;
}
 
Example 2
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
private static Message buildMessage(final int messageSize) {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes());

    return msg;
}
 
Example 3
Source File: SendMsgStatusCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
private static Message buildMessage(final String topic, final int messageSize) {
    Message msg = new Message();
    msg.setTopic(topic);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 11) {
        sb.append("hello jodie");
    }
    msg.setBody(sb.toString().getBytes());
    return msg;
}
 
Example 4
Source File: Producer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));

    return msg;
}
 
Example 5
Source File: TransactionProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));

    return msg;
}
 
Example 6
Source File: SendMsgStatusCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic(topic);

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 11) {
        sb.append("hello jodie");
    }
    msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET));
    return msg;
}
 
Example 7
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 8
Source File: Producer.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(final int messageSize) {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes());

    return msg;
}
 
Example 9
Source File: TransactionProducer.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(final int messageSize) {
    Message msg = new Message();
    msg.setTopic("BenchmarkTest");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < messageSize; i += 10) {
        sb.append("hello baby");
    }

    msg.setBody(sb.toString().getBytes());

    return msg;
}
 
Example 10
Source File: MqProducer.java    From RocketMqCurrencyBoot with Apache License 2.0 4 votes vote down vote up
/**
 *  发送数据到MQ方法  
 * 
 * @param Topic   队列名称
 * @param Tags	     标签名称
 * @param body	  发送的数据  推荐 JSOM 或者 XML 结构
 * @param Encoding  数据编码格式  默认UTF-8
 * @return   响应信息进行了内部处理  确认已经保存到 MQ 并且    日志已经记录  只要值不是NULL 就是成功发送
 * @throws UnsupportedEncodingException  转换字符集出错  请检查是否可以转换 
 */
public SendResult send(String Topic, String Tags, String body, String Encoding)
		throws UnsupportedEncodingException
{

	String loggerString = MessageFormat.format(
			"将要发送到Mq的数据    Topic={0}   Tags={1}   body={2}  Encoding={3} ", Topic, Tags, body,
			Encoding);

	if (Encoding == null || "".equals(Encoding))
	{
		Encoding = "UTF-8";
	}

	if (Tags == null || "".equals(Tags))
	{
		Tags = "*";
	}

	LOGGER.info(loggerString);

	Message me = new Message();
	// 标示
	me.setTopic(Topic);
	// 标签
	me.setTags(Tags);
	// 内容
	me.setBody(body.getBytes(Encoding));
	// 发送信息到MQ SendResult 是当前发送的状态 官方说 不出异常 就是成功
	SendResult sendResult = null;
	try
	{
		if (producer instanceof TransactionMQProducer)
		{
			sendResult = ((TransactionMQProducer) producer).sendMessageInTransaction(me,
					transactionExecuter, null);

		}
		else
		{
			sendResult = ((DefaultMQProducer) producer).send(me);
		}
	}
	catch (Exception e)
	{
		LOGGER.error(" 发送 数据给MQ出现异常  " + loggerString, e);
	}
	// 当消息发送失败时如何处理 getSendStatus 获取发送的状态
	if (sendResult == null || sendResult.getSendStatus() != SendStatus.SEND_OK)
	{
		LOGGER.info(loggerString + "发送消息失败" + " MQ状态值  SendResult=" + sendResult);
		sendResult = null;
	}
	LOGGER.info("发送到MQ成功" + sendResult);
	return sendResult;
}