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


Java Message.putUserProperty方法代码示例

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


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

示例1: sendFilterMessage

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * 发送消息
 * @return
 */
public String sendFilterMessage(){
    DefaultMQProducer producer=new DefaultMQProducer(RocketMQConfiguration.ROCKETMQ_GROUP);
    producer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    producer.setVipChannelEnabled(false);
    try {
        producer.start();
        for (int i = 0; i <10 ; i++) {
            Message message1 = new Message(RocketMQConfiguration.ROCKETMQ_TOPIC,"filter",null, ("lovecws"+i).getBytes());
            message1.putUserProperty("a",String.valueOf(i));
            SendResult sendResult = producer.send(message1);
            System.out.println(sendResult);
        }
        return null;
    } catch (MQClientException |InterruptedException| RemotingException |MQBrokerException e) {
        e.printStackTrace();
        System.exit(1);
    }finally {
        producer.shutdown();
    }
    return null;
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:26,代码来源:RocketMQFilterProcedure.java

示例2: testSendChinaUserProp

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * @since version3.4.6
 */
@Test
public void testSendChinaUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinzhi";
    msg.putUserProperty(msgKey, msgValue);

    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());

    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);

    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListner().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:MessageUserPropIT.java

示例3: main

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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",
                "TagA",
                "OrderID001",
                "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));

            msg.putUserProperty("SequenceId", String.valueOf(i));
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    producer.shutdown();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:21,代码来源:Producer.java

示例4: testSendEnglishUserProp

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * @since version3.4.6
 */
@Test
public void testSendEnglishUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinValue";
    msg.putUserProperty(msgKey, msgValue);

    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListner());

    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);

    consumer.getListner().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListner().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:MessageUserPropIT.java

示例5: testEncodeDecodeSingle

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testEncodeDecodeSingle() throws Exception {
    Message message = new Message("topic", "body".getBytes());
    message.setFlag(12);
    message.putUserProperty("key", "value");
    byte[] bytes = MessageDecoder.encodeMessage(message);
    ByteBuffer buffer = ByteBuffer.allocate(bytes.length);
    buffer.put(bytes);
    buffer.flip();
    Message newMessage = MessageDecoder.decodeMessage(buffer);

    assertTrue(message.getFlag() == newMessage.getFlag());
    assertTrue(newMessage.getProperty("key").equals(newMessage.getProperty("key")));
    assertTrue(Arrays.equals(newMessage.getBody(), message.getBody()));
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:16,代码来源:MessageEncodeDecodeTest.java

示例6: testSend20kChinaPropMsg

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * @since version3.4.6
 */
@Test(expected = org.apache.rocketmq.client.exception.MQBrokerException.class)
public void testSend20kChinaPropMsg() throws Exception {
    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(32 * 1024 + 1));
    producer.send(msg);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:10,代码来源:ChinaPropIT.java

示例7: testSend10kChinaPropMsg

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
 * @since version3.4.6
 */
@Test
public void testSend10kChinaPropMsg() {

    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:16,代码来源:ChinaPropIT.java

示例8: testSendMsgWithUserProperty

import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testSendMsgWithUserProperty() {
    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
        sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:12,代码来源:MessageExceptionIT.java


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