当前位置: 首页>>代码示例>>Java>>正文


Java Message.setTags方法代码示例

本文整理汇总了Java中org.apache.rocketmq.common.message.Message.setTags方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setTags方法的具体用法?Java Message.setTags怎么用?Java Message.setTags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.rocketmq.common.message.Message的用法示例。


在下文中一共展示了Message.setTags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMsg

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
public static List<Object> getMsg(String topic, int msgSize, String tag) {
    List<Object> msgs = new ArrayList<Object>();
    while (msgSize > 0) {
        Message msg = new Message(topic, (index++).toString().getBytes());
        if (tag != null) {
            msg.setTags(tag);
        }
        msgs.add(msg);
        msgSize--;
    }

    return msgs;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:14,代码来源:MQMessageFactory.java

示例2: testAppendMessageBatchEndOfFile

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testAppendMessageBatchEndOfFile() throws Exception{
    List<Message>  messages = new ArrayList<>();
    String topic = "test-topic";
    int queue= 0;
    for (int i = 0; i < 10; i++) {
        Message msg = new Message();
        msg.setBody("body".getBytes());
        msg.setTopic(topic);
        msg.setTags("abc");
        messages.add(msg);
    }
    MessageExtBatch messageExtBatch = new MessageExtBatch();
    messageExtBatch.setTopic(topic);
    messageExtBatch.setQueueId(queue);
    messageExtBatch.setBornTimestamp(System.currentTimeMillis());
    messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1",123));
    messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1",124));
    messageExtBatch.setBody(MessageDecoder.encodeMessages(messages));

    messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch));
    ByteBuffer buff = ByteBuffer.allocate(1024 * 10);
    //encounter end of file when append half of the data
    AppendMessageResult result = callback.doAppend(0, buff, 1000, messageExtBatch);
    assertEquals(AppendMessageStatus.END_OF_FILE, result.getStatus());
    assertEquals(0, result.getWroteOffset());
    assertEquals(0, result.getLogicsOffset());
    assertEquals(1000, result.getWroteBytes());
    assertEquals(8, buff.position()); //write blank size and magic value

    assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:33,代码来源:AppendCallbackTest.java

示例3: genMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
private Message genMessage(String topic, String tag, Object msgObj) {
    String messageKey= "";
    try {
        Field[] fields = msgObj.getClass().getDeclaredFields();
        for (Field field : fields) {
            Annotation[] allFAnnos= field.getAnnotations();
            if(allFAnnos.length > 0) {
                for (int i = 0; i < allFAnnos.length; i++) {
                    if(allFAnnos[i].annotationType().equals(MQKey.class)) {
                        field.setAccessible(true);
                        MQKey mqKey = MQKey.class.cast(allFAnnos[i]);
                        messageKey = StringUtils.isEmpty(mqKey.prefix()) ? field.get(msgObj).toString() : (mqKey.prefix() + field.get(msgObj).toString());
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("parse key error : {}" , e.getMessage());
    }
    String str = gson.toJson(msgObj);
    if(StringUtils.isEmpty(topic)) {
        if(StringUtils.isEmpty(getTopic())) {
            throw new RuntimeException("no topic defined to send this message");
        }
        topic = getTopic();
    }
    Message message = new Message(topic, str.getBytes(Charset.forName("utf-8")));
    if (!StringUtils.isEmpty(tag)) {
        message.setTags(tag);
    } else if (!StringUtils.isEmpty(getTag())) {
        message.setTags(getTag());
    }
    if(StringUtils.isNotEmpty(messageKey)) {
        message.setKeys(messageKey);
    }
    return message;
}
 
开发者ID:maihaoche,项目名称:rocketmq-spring-boot-starter,代码行数:38,代码来源:AbstractMQProducer.java

示例4: testBatchSend_CheckProperties

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testBatchSend_CheckProperties() throws Exception {
    List<Message> messageList = new ArrayList<>();
    Message message = new Message();
    message.setTopic(topic);
    message.setKeys("keys123");
    message.setTags("tags123");
    message.setWaitStoreMsgOK(false);
    message.setBuyerId("buyerid123");
    message.setFlag(123);
    message.setBody("body".getBytes());
    messageList.add(message);


    DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
    SendResult sendResult = producer.send(messageList);
    Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());

    String[] offsetIds = sendResult.getOffsetMsgId().split(",");
    String[] msgIds = sendResult.getMsgId().split(",");
    Assert.assertEquals(messageList.size(), offsetIds.length);
    Assert.assertEquals(messageList.size(), msgIds.length);

    Thread.sleep(2000);

    Message messageByOffset = producer.viewMessage(offsetIds[0]);
    Message messageByMsgId = producer.viewMessage(topic, msgIds[0]);

    System.out.println(messageByOffset);
    System.out.println(messageByMsgId);

    Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic());
    Assert.assertEquals(message.getTopic(), messageByOffset.getTopic());

    Assert.assertEquals(message.getKeys(), messageByOffset.getKeys());
    Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys());

    Assert.assertEquals(message.getTags(), messageByOffset.getTags());
    Assert.assertEquals(message.getTags(), messageByMsgId.getTags());

    Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK());
    Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK());

    Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId());
    Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId());

    Assert.assertEquals(message.getFlag(), messageByOffset.getFlag());
    Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag());
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:50,代码来源:BatchSendIT.java

示例5: testAppendMessageBatchSucc

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testAppendMessageBatchSucc() throws Exception {
    List<Message>  messages = new ArrayList<>();
    String topic = "test-topic";
    int queue= 0;
    for (int i = 0; i < 10; i++) {
        Message msg = new Message();
        msg.setBody("body".getBytes());
        msg.setTopic(topic);
        msg.setTags("abc");
        messages.add(msg);
    }
    MessageExtBatch messageExtBatch = new MessageExtBatch();
    messageExtBatch.setTopic(topic);
    messageExtBatch.setQueueId(queue);
    messageExtBatch.setBornTimestamp(System.currentTimeMillis());
    messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1",123));
    messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1",124));
    messageExtBatch.setBody(MessageDecoder.encodeMessages(messages));

    messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch));
    ByteBuffer buff = ByteBuffer.allocate(1024 * 10);
    AppendMessageResult allresult = callback.doAppend(0, buff, 1024 * 10, messageExtBatch);

    assertEquals(AppendMessageStatus.PUT_OK, allresult.getStatus());
    assertEquals(0, allresult.getWroteOffset());
    assertEquals(0, allresult.getLogicsOffset());
    assertEquals(buff.position(), allresult.getWroteBytes());

    assertEquals(messages.size(), allresult.getMsgNum());

    Set<String> msgIds = new HashSet<>();
    for (String msgId: allresult.getMsgId().split(",")) {
        assertEquals(32, msgId.length());
        msgIds.add(msgId);
    }
    assertEquals(messages.size(), msgIds.size());

    List<MessageExt> decodeMsgs = MessageDecoder.decodes((ByteBuffer) buff.flip());
    assertEquals(decodeMsgs.size(), decodeMsgs.size());
    long queueOffset = decodeMsgs.get(0).getQueueOffset();
    long storeTimeStamp = decodeMsgs.get(0).getStoreTimestamp();
    for (int i = 0; i < messages.size(); i++) {
        assertEquals(messages.get(i).getTopic(), decodeMsgs.get(i).getTopic());
        assertEquals(new String(messages.get(i).getBody()), new String(decodeMsgs.get(i).getBody()));
        assertEquals(messages.get(i).getTags(), decodeMsgs.get(i).getTags());

        assertEquals(messageExtBatch.getBornHostNameString(), decodeMsgs.get(i).getBornHostNameString());

        assertEquals(messageExtBatch.getBornTimestamp(), decodeMsgs.get(i).getBornTimestamp());
        assertEquals(storeTimeStamp, decodeMsgs.get(i).getStoreTimestamp());
        assertEquals(queueOffset++, decodeMsgs.get(i).getQueueOffset());
    }

}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:56,代码来源:AppendCallbackTest.java


注:本文中的org.apache.rocketmq.common.message.Message.setTags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。