public void testPrefetchValueOne() throws Exception {

    ActiveMQTopic consumerDestination = new ActiveMQTopic(TOPIC_NAME + "?consumer.prefetchSize=1");
    consumer = session.createConsumer(consumerDestination);

    // add a consumer to the slow consumer advisory topic.
    ActiveMQTopic slowConsumerAdvisoryTopic =
        AdvisorySupport.getSlowConsumerAdvisoryTopic(destination);
    MessageConsumer slowConsumerAdvisory = session.createConsumer(slowConsumerAdvisoryTopic);

    // publish 2 messages
    Message txtMessage = session.createTextMessage("Sample Text Message");
    for (int i = 0; i < 2; i++) {
      producer.send(txtMessage);
    }

    // consume 2 messages
    for (int i = 0; i < 2; i++) {
      Message receivedMsg = consumer.receive(100);
      Assert.assertNotNull("received msg " + i + " should not be null", receivedMsg);
    }

    // check for "slow consumer" advisory message
    Message slowAdvisoryMessage = slowConsumerAdvisory.receive(100);
    Assert.assertNull(
        "should not have received a slow consumer advisory message", slowAdvisoryMessage);
  }
コード例 #2
0
ファイル: Test.java プロジェクト: heylichen/amq
  public static void main(String[] args) throws Exception {
    Test advisory = new Test();
    Session session = advisory.getSession();
    for (String job : advisory.jobs) {

      ActiveMQDestination destination = (ActiveMQDestination) session.createQueue("JOBS." + job);

      Destination consumerTopic = AdvisorySupport.getConsumerAdvisoryTopic(destination);
      System.out.println("Subscribing to advisory " + consumerTopic);
      MessageConsumer consumerAdvisory = session.createConsumer(consumerTopic);
      consumerAdvisory.setMessageListener(new ConsumerAdvisoryListener());

      Destination noConsumerTopic = AdvisorySupport.getNoQueueConsumersAdvisoryTopic(destination);
      System.out.println("Subscribing to advisory " + noConsumerTopic);
      MessageConsumer noConsumerAdvisory = session.createConsumer(noConsumerTopic);
      noConsumerAdvisory.setMessageListener(new NoConsumerAdvisoryListener());
    }
  }
コード例 #3
0
  public void testAdvisory() throws Exception {
    MessageConsumer advConsumer =
        session.createConsumer(AdvisorySupport.getMasterBrokerAdvisoryTopic());

    master.stop();
    assertTrue("slave started", slaveStarted.await(60, TimeUnit.SECONDS));
    LOG.info("slave started");
    Message advisoryMessage = advConsumer.receive(5000);
    LOG.info("received " + advisoryMessage);
    assertNotNull("Didn't received advisory", advisoryMessage);
  }