Java Code Examples for io.openmessaging.Message#putProperties()

The following examples show how to use io.openmessaging.Message#putProperties() . 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: V7ProducerTester.java    From coding-snippets with MIT License 4 votes vote down vote up
@Override
        public void run() {
            while (true) {
                try {
                    String queueOrTopic;
                    Message message;
                    if (sendNum % 10 == 0) {
                        queueOrTopic = "QUEUE_" + random.nextInt(10);
                        message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    } else {
                        queueOrTopic = "TOPIC_" + random.nextInt(100);
                        message = producer.createBytesMessageToTopic(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    }
                    //测试多个header,properties

                    message.putHeaders(MessageHeader.SHARDING_KEY, queueOrTopic);
                    message.putHeaders(MessageHeader.BORN_HOST, queueOrTopic);
                    message.putHeaders(MessageHeader.MESSAGE_ID, queueOrTopic);
                    message.putProperties("PRO_OFFSET", "PRODUCER5_719");
                    message.putProperties("jdljknw", "ys0yz2b");
                    message.putProperties("jdlrvo9", "ys06a3l");
                    
                    if(sendNum % 10 == 0 && sendNum < 500){
                    	message.putHeaders(MessageHeader.MESSAGE_ID, "1828oz6vk46cuupruzgmdh1okq55i7sh5wozy3sejk47vsv2xt4rh9aq5cjevpcv9m0893a7mlop27y1mqkltvy4f2yl1jjbz0ce2p8shsep31avbar64p3j8nw5vaplkqyr8w1qo47ljxa1pp1nqrlmqgfettpc82d2ox2b3fh45w7ynui18v12q9u4ow4lrzafdr6rar2ae5lnjr3aizrr09qnn75r4cjmcy3to5hgtcvcw2m7if7so2tvnvpblaincanybhiwm5i8agt9idsh6al5vvo8c45atw2p5293e0d340iyebnremgbsr5f3wen8btzw6qhoqybkozgt0724ag2lbh740gykvwvibyitazlka4yz4u9cloey809xl4bd0jasuzicd83h3v7xo5s9ogj4tlcwb8ycr5gi27uxua5jj99qn3t18pm62hpmadrxrzg0d5oldd6mdruzpetuupl8wo8710rf48qapptr6dri3g4v27mdp2hz2x0ba4ce7pv4nndg1h337bemrdsjn77nw91eztzujyz5zgvvqnh678xflfuikpjngg04g9wbj705vvn9bxgq4a4n0pr29r6a79k70iqi34o7aovogwek3u7jvjlia2p1e5rrqdo6e8r1q7ujrn3dtphvxe0pjlobddygbsummbdk0spjh734h3mqs78ak45uanzt8t6av9k8vicxpzb4dh1vj0t7xvrj7882nsyn1w0is5u3ymx9sv2pjkyj0pcisqnsllo080bifzbi9q1m82x355uvcwqa2ohjb62l28yh2uacp3nnjevsf7e999h1m1yfv4fzrwkxls7lq0aiv6borgy1xd7g93p8lxrnxtspi24os2rndvy5x6nu67t8fxnenb2se3j31o3v6dphh3xo9xvkkjjmlog3o18w977f34g8crw7dfimwzwiybdscaputs1ols31ujy34bwg529yqroajttca4mnzlztagwc");
                    	message.putHeaders(MessageHeader.START_TIME, queueOrTopic);
                    	message.putProperties("PRO_OFF", "1828oz6vk46cuupruzgmdh1okq55i7sh5wozy3sejk47vsv2xt4rh9aq5cjevpcv9m0893a7mlop27y1mqkltvy4f2yl1jjbz0ce2p8shsep31avbar64p3j8nw5vaplkqyr8w1qo47ljxa1pp1nqrlmqgfettpc82d2ox2b3fh45w7ynui18v12q9u4ow4lrzafdr6rar2ae5lnjr3aizrr09qnn75r4cjmcy3to5hgtcvcw2m7if7so2tvnvpblaincanybhiwm5i8agt9idsh6al5vvo8c45atw2p5293e0d340iyebnremgbsr5f3wen8btzw6qhoqybkozgt0724ag2lbh740gykvwvibyitazlka4yz4u9cloey809xl4bd0jasuzicd83h3v7xo5s9ogj4tlcwb8ycr5gi27uxua5jj99qn3t18pm62hpmadrxrzg0d5oldd6mdruzpetuupl8wo8710rf48qapptr6dri3g4v27mdp2hz2x0ba4ce7pv4nndg1h337bemrdsjn77nw91eztzujyz5zgvvqnh678xflfuikpjngg04g9wbj705vvn9bxgq4a4n0pr29r6a79k70iqi34o7aovogwek3u7jvjlia2p1e5rrqdo6e8r1q7ujrn3dtphvxe0pjlobddygbsummbdk0spjh734h3mqs78ak45uanzt8t6av9k8vicxpzb4dh1vj0t7xvrj7882nsyn1w0is5u3ymx9sv2pjkyj0pcisqnsllo080bifzbi9q1m82x355uvcwqa2ohjb62l28yh2uacp3nnjevsf7e999h1m1yfv4fzrwkxls7lq0aiv6borgy1xd7g93p8lxrnxtspi24os2rndvy5x6nu67t8fxnenb2se3j31o3v6dphh3xo9xvkkjjmlog3o18w977f34g8crw7dfimwzwiybdscaputs1ols31ujy34bwg529yqroajttca4mnzlztagwc");
                    }
                    
                    /**
                     * 消息主体 :“生产者线程名_偏移” 的字节.
                     * 对于label(线程名)和queue/topic的组合来说来说,偏移是一直累加的,0、1、2、3……    
                     * 即每个线程对于每个queue/topic的消息中偏移都是一个连续的累加的。
                     */
//                    Message message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
//                    logger.debug("queueOrTopic:{} offset:{}", queueOrTopic, label + "_" + offsets.get(queueOrTopic));
                    //每产生一个消息,该bucket对应的便偏移+1
                    offsets.put(queueOrTopic, offsets.get(queueOrTopic) + 1);
                    producer.send(message);
                    sendNum++;
                    if (sendNum >= Constants.PRO_MAX) {
                    	//自己测试时记得关闭,不然没法删除持有的文件。实测时kill进程,没有这个问题
//                    	if(sendNum%20000 == 0){
//                    		System.out.println(Thread.currentThread().getName()+" 发送:"+sendNum);
//                    		String log =Thread.currentThread().getName()+" 发送:"+sendNum;
//                    		logger.info(log);
//                    	}
                    	producer.flush();
                        break;
                    }
                } catch (Exception e) {
                    logger.error("Error occurred in the sending process", e);
                    break;
                }
            }
        }
 
Example 2
Source File: ProducerTester.java    From coding-snippets with MIT License 4 votes vote down vote up
@Override
        public void run() {
            while (true) {
                try {
                    String queueOrTopic;
                    Message message;
                    if (sendNum % 10 == 0) {
                        queueOrTopic = "QUEUE_" + random.nextInt(10);
                        message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    } else {
                        queueOrTopic = "TOPIC_" + random.nextInt(100);
                        message = producer.createBytesMessageToTopic(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    }
                    //测试多个header,properties
                    message.putHeaders(MessageHeader.SHARDING_KEY, queueOrTopic);
                    message.putHeaders(MessageHeader.BORN_HOST, queueOrTopic);
                    message.putHeaders(MessageHeader.MESSAGE_ID, queueOrTopic);
                    message.putProperties(queueOrTopic, queueOrTopic);
                    message.putProperties(queueOrTopic+sendNum, queueOrTopic);
                    /**
                     * 消息主体 :“生产者线程名_偏移” 的字节.
                     * 对于label(线程名)和queue/topic的组合来说来说,偏移是一直累加的,0、1、2、3……    
                     * 即每个线程对于每个queue/topic的消息中偏移都是一个连续的累加的。
                     */
//                    Message message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
//                    logger.debug("queueOrTopic:{} offset:{}", queueOrTopic, label + "_" + offsets.get(queueOrTopic));
                    //每产生一个消息,该bucket对应的便偏移+1
                    offsets.put(queueOrTopic, offsets.get(queueOrTopic) + 1);
                    producer.send(message);
                    sendNum++;
                    if(sendNum == 3000000){
                    	System.out.println();
                    }
                    if (sendNum >= Constants.PRO_MAX) {
                    	//自己测试时记得关闭,不然没法删除持有的文件。实测时kill进程,没有这个问题
//                    	if(sendNum%20000 == 0){
//                    		System.out.println(Thread.currentThread().getName()+" 发送:"+sendNum);
//                    		String log =Thread.currentThread().getName()+" 发送:"+sendNum;
//                    		logger.info(log);
//                    	}
                    	producer.flush();
                        break;
                    }
                } catch (Exception e) {
                    logger.error("Error occurred in the sending process", e);
                    break;
                }
            }
        }
 
Example 3
Source File: V6ProducerTester.java    From coding-snippets with MIT License 4 votes vote down vote up
@Override
        public void run() {
            while (true) {
                try {
                    String queueOrTopic;
                    Message message;
                    if (sendNum % 10 == 0) {
                        queueOrTopic = "QUEUE_" + random.nextInt(10);
                        message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    } else {
                        queueOrTopic = "TOPIC_" + random.nextInt(100);
                        message = producer.createBytesMessageToTopic(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    }
                    //测试多个header,properties

                    message.putHeaders(MessageHeader.SHARDING_KEY, queueOrTopic);
                    message.putHeaders(MessageHeader.BORN_HOST, queueOrTopic);
                    message.putHeaders(MessageHeader.MESSAGE_ID, queueOrTopic);
                    message.putProperties("PRO_OFFSET", "PRODUCER5_719");
                    message.putProperties("jdljknw", "ys0yz2b");
                    message.putProperties("jdlrvo9", "ys06a3l");
                    
                    if(sendNum % 10 == 0 && sendNum < 500){
                    	message.putHeaders(MessageHeader.MESSAGE_ID, "1828oz6vk46cuupruzgmdh1okq55i7sh5wozy3sejk47vsv2xt4rh9aq5cjevpcv9m0893a7mlop27y1mqkltvy4f2yl1jjbz0ce2p8shsep31avbar64p3j8nw5vaplkqyr8w1qo47ljxa1pp1nqrlmqgfettpc82d2ox2b3fh45w7ynui18v12q9u4ow4lrzafdr6rar2ae5lnjr3aizrr09qnn75r4cjmcy3to5hgtcvcw2m7if7so2tvnvpblaincanybhiwm5i8agt9idsh6al5vvo8c45atw2p5293e0d340iyebnremgbsr5f3wen8btzw6qhoqybkozgt0724ag2lbh740gykvwvibyitazlka4yz4u9cloey809xl4bd0jasuzicd83h3v7xo5s9ogj4tlcwb8ycr5gi27uxua5jj99qn3t18pm62hpmadrxrzg0d5oldd6mdruzpetuupl8wo8710rf48qapptr6dri3g4v27mdp2hz2x0ba4ce7pv4nndg1h337bemrdsjn77nw91eztzujyz5zgvvqnh678xflfuikpjngg04g9wbj705vvn9bxgq4a4n0pr29r6a79k70iqi34o7aovogwek3u7jvjlia2p1e5rrqdo6e8r1q7ujrn3dtphvxe0pjlobddygbsummbdk0spjh734h3mqs78ak45uanzt8t6av9k8vicxpzb4dh1vj0t7xvrj7882nsyn1w0is5u3ymx9sv2pjkyj0pcisqnsllo080bifzbi9q1m82x355uvcwqa2ohjb62l28yh2uacp3nnjevsf7e999h1m1yfv4fzrwkxls7lq0aiv6borgy1xd7g93p8lxrnxtspi24os2rndvy5x6nu67t8fxnenb2se3j31o3v6dphh3xo9xvkkjjmlog3o18w977f34g8crw7dfimwzwiybdscaputs1ols31ujy34bwg529yqroajttca4mnzlztagwc");
                    	message.putHeaders(MessageHeader.START_TIME, queueOrTopic);
                    	message.putProperties("PRO_OFF", "1828oz6vk46cuupruzgmdh1okq55i7sh5wozy3sejk47vsv2xt4rh9aq5cjevpcv9m0893a7mlop27y1mqkltvy4f2yl1jjbz0ce2p8shsep31avbar64p3j8nw5vaplkqyr8w1qo47ljxa1pp1nqrlmqgfettpc82d2ox2b3fh45w7ynui18v12q9u4ow4lrzafdr6rar2ae5lnjr3aizrr09qnn75r4cjmcy3to5hgtcvcw2m7if7so2tvnvpblaincanybhiwm5i8agt9idsh6al5vvo8c45atw2p5293e0d340iyebnremgbsr5f3wen8btzw6qhoqybkozgt0724ag2lbh740gykvwvibyitazlka4yz4u9cloey809xl4bd0jasuzicd83h3v7xo5s9ogj4tlcwb8ycr5gi27uxua5jj99qn3t18pm62hpmadrxrzg0d5oldd6mdruzpetuupl8wo8710rf48qapptr6dri3g4v27mdp2hz2x0ba4ce7pv4nndg1h337bemrdsjn77nw91eztzujyz5zgvvqnh678xflfuikpjngg04g9wbj705vvn9bxgq4a4n0pr29r6a79k70iqi34o7aovogwek3u7jvjlia2p1e5rrqdo6e8r1q7ujrn3dtphvxe0pjlobddygbsummbdk0spjh734h3mqs78ak45uanzt8t6av9k8vicxpzb4dh1vj0t7xvrj7882nsyn1w0is5u3ymx9sv2pjkyj0pcisqnsllo080bifzbi9q1m82x355uvcwqa2ohjb62l28yh2uacp3nnjevsf7e999h1m1yfv4fzrwkxls7lq0aiv6borgy1xd7g93p8lxrnxtspi24os2rndvy5x6nu67t8fxnenb2se3j31o3v6dphh3xo9xvkkjjmlog3o18w977f34g8crw7dfimwzwiybdscaputs1ols31ujy34bwg529yqroajttca4mnzlztagwc");
                    }
                    
                    /**
                     * 消息主体 :“生产者线程名_偏移” 的字节.
                     * 对于label(线程名)和queue/topic的组合来说来说,偏移是一直累加的,0、1、2、3……    
                     * 即每个线程对于每个queue/topic的消息中偏移都是一个连续的累加的。
                     */
//                    Message message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
//                    logger.debug("queueOrTopic:{} offset:{}", queueOrTopic, label + "_" + offsets.get(queueOrTopic));
                    //每产生一个消息,该bucket对应的便偏移+1
                    offsets.put(queueOrTopic, offsets.get(queueOrTopic) + 1);
                    producer.send(message);
                    sendNum++;
                    if (sendNum >= Constants.PRO_MAX) {
                    	//自己测试时记得关闭,不然没法删除持有的文件。实测时kill进程,没有这个问题
//                    	if(sendNum%20000 == 0){
//                    		System.out.println(Thread.currentThread().getName()+" 发送:"+sendNum);
//                    		String log =Thread.currentThread().getName()+" 发送:"+sendNum;
//                    		logger.info(log);
//                    	}
                    	producer.flush();
                        break;
                    }
                } catch (Exception e) {
                    logger.error("Error occurred in the sending process", e);
                    break;
                }
            }
        }
 
Example 4
Source File: V5ProducerTester.java    From coding-snippets with MIT License 4 votes vote down vote up
@Override
        public void run() {
            while (true) {
                try {
                    String queueOrTopic;
                    Message message;
                    if (sendNum % 10 == 0) {
                        queueOrTopic = "QUEUE_" + random.nextInt(10);
                        message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    } else {
//                        queueOrTopic = "TOPIC_" + random.nextInt(10);
                     // 修改上限为100
                        queueOrTopic = "TOPIC_" + random.nextInt(100);
                        message = producer.createBytesMessageToTopic(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
                    }
                    //测试多个header,properties
                    message.putHeaders(MessageHeader.SHARDING_KEY, queueOrTopic);
                    message.putHeaders(MessageHeader.BORN_HOST, queueOrTopic);
                    message.putHeaders(MessageHeader.MESSAGE_ID, queueOrTopic);
                    message.putProperties(queueOrTopic, queueOrTopic);
                    message.putProperties(queueOrTopic+sendNum, queueOrTopic);
                    /**
                     * 消息主体 :“生产者线程名_偏移” 的字节.
                     * 对于label(线程名)和queue/topic的组合来说来说,偏移是一直累加的,0、1、2、3……
                     * 即每个线程对于每个queue/topic的消息中偏移都是一个连续的累加的。
                     */
//                    Message message = producer.createBytesMessageToQueue(queueOrTopic, (label + "_" + offsets.get(queueOrTopic)).getBytes());
//                    logger.debug("queueOrTopic:{} offset:{}", queueOrTopic, label + "_" + offsets.get(queueOrTopic));
                    //每产生一个消息,该bucket对应的便偏移+1
                    offsets.put(queueOrTopic, offsets.get(queueOrTopic) + 1);
                    producer.send(message);
                    sendNum++;
                    if (sendNum >= Constants.PRO_MAX) {
                    	//自己测试时记得关闭,不然没法删除持有的文件。实测时kill进程,没有这个问题
                    	producer.flush();
                        break;
                    }
                } catch (Exception e) {
                    logger.error("Error occurred in the sending process", e);
                    break;
                }
            }
        }