Exemplo n.º 1
0
 @Override
 public boolean testMessage(Message msg) {
   if (msg.hasHeader()) {
     MessageHeader header = msg.getHeader();
     if (header.hasProperties()) {
       Map<String, ByteString> props = MapUtils.buildMap(header.getProperties());
       ByteString value = props.get(OPT_MOD);
       if (null == value) {
         return false;
       }
       int intValue = Integer.valueOf(value.toStringUtf8());
       if (0 != intValue) {
         return false;
       }
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Exemplo n.º 2
0
 private void publishNums(ByteString topic, int start, int num, int M) throws Exception {
   for (int i = 1; i <= num; i++) {
     PubSubProtocol.Map.Builder propsBuilder =
         PubSubProtocol.Map.newBuilder()
             .addEntries(
                 PubSubProtocol.Map.Entry.newBuilder()
                     .setKey(OPT_MOD)
                     .setValue(ByteString.copyFromUtf8(String.valueOf((start + i) % M))));
     MessageHeader.Builder headerBuilder = MessageHeader.newBuilder().setProperties(propsBuilder);
     Message msg =
         Message.newBuilder()
             .setBody(ByteString.copyFromUtf8(String.valueOf((start + i))))
             .setHeader(headerBuilder)
             .build();
     publisher.publish(topic, msg);
   }
 }