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


Java Message.setTopic方法代码示例

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


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

示例1: buildMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
private static Message buildMessage(final int messageSize, final String topic) throws UnsupportedEncodingException {
    Message msg = new Message();
    msg.setTopic(topic);

    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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:14,代码来源:Producer.java

示例2: buildMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:14,代码来源:TransactionProducer.java

示例3: buildMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:12,代码来源:SendMsgStatusCommand.java

示例4: 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

示例5: 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

示例6: 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.setTopic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。