Ejemplo n.º 1
0
  @Test
  public void testPoll3() throws InterruptedException {
    // 插入1条消息
    String myType = TYPE + "_";
    SwallowMessage myTypeMsg = createMessage();
    myTypeMsg.setType(myType);
    messageDAO.saveMessage(TOPIC_NAME, myTypeMsg);

    Set<String> messageTypeSet = new HashSet<String>();
    messageTypeSet.add(myType);
    ConsumerInfo consumerInfo =
        new ConsumerInfo(
            "consumerId", Destination.topic(TOPIC_NAME), ConsumerType.DURABLE_AT_LEAST_ONCE);
    BlockingQueue<SwallowMessage> queue =
        swallowBuffer.createMessageQueue(
            consumerInfo,
            tailMessageId,
            tailMessageId,
            MessageFilter.createInSetMessageFilter(messageTypeSet));

    SwallowMessage m = queue.poll(500, TimeUnit.MILLISECONDS);
    while (m == null) {
      m = queue.poll(50, TimeUnit.MILLISECONDS);
    }
    Assert.assertEquals(myType, m.getType());
  }
Ejemplo n.º 2
0
 private static SwallowMessage createMessage() {
   SwallowMessage message = new SwallowMessage();
   message.setContent("this is a SwallowMessage");
   message.setGeneratedTime(new Date());
   HashMap<String, String> map = new HashMap<String, String>();
   map.put("property-key", "property-value");
   message.setProperties(map);
   message.setSha1("sha-1 string");
   message.setVersion("0.6.0");
   message.setType(TYPE);
   return message;
 }