@Override
    protected Message createMessage(int i) throws Exception {
      TextMessage msg = createTextMessage(this.session, "Message-" + i);
      if (selectors.size() > 0) {
        String value = getRandomKey();
        msg.setStringProperty("SYMBOL", value);
        AtomicInteger currentCount = selectorCounts.get(value);
        currentCount.incrementAndGet();
      }

      return msg;
    }
  public void testJMX() throws Exception {
    clearSelectorCacheFiles();
    // borkerA is local and brokerB is remote
    bridgeAndConfigureBrokers("BrokerA", "BrokerB");
    startAllBrokers();
    waitForBridgeFormation();

    createConsumer(
        "BrokerB", createDestination("Consumer.B.VirtualTopic.tempTopic", false), "foo = 'bar'");

    final BrokerService brokerA = brokers.get("BrokerA").broker;

    String testQueue = "queue://Consumer.B.VirtualTopic.tempTopic";
    VirtualDestinationSelectorCacheViewMBean cache =
        getVirtualDestinationSelectorCacheMBean(brokerA);
    Set<String> selectors = cache.selectorsForDestination(testQueue);

    assertEquals(1, selectors.size());
    assertTrue(selectors.contains("foo = 'bar'"));

    boolean removed = cache.deleteSelectorForDestination(testQueue, "foo = 'bar'");
    assertTrue(removed);

    selectors = cache.selectorsForDestination(testQueue);
    assertEquals(0, selectors.size());

    createConsumer(
        "BrokerB",
        createDestination("Consumer.B.VirtualTopic.tempTopic", false),
        "ceposta = 'redhat'");

    Wait.waitFor(
        new Wait.Condition() {

          Destination dest =
              brokerA.getDestination(new ActiveMQQueue("Consumer.B.VirtualTopic.tempTopic"));

          @Override
          public boolean isSatisified() throws Exception {
            return dest.getConsumers().size() == 2;
          }
        },
        500);

    selectors = cache.selectorsForDestination(testQueue);
    assertEquals(1, selectors.size());
    cache.deleteAllSelectorsForDestination(testQueue);
    selectors = cache.selectorsForDestination(testQueue);
    assertEquals(0, selectors.size());
  }
 public void addMessageProperty(String value) {
   if (!this.selectors.contains(value)) {
     selectors.add(value);
     selectorCounts.put(value, new AtomicInteger(0));
   }
 }
コード例 #4
0
  @Test
  public void testFetchLast() {
    try {

      String neId =
          "1005255"; // KLNNMS02(cpuusage=YES cpu1min=YES memutil=YES) KLNNMS05(cpuusage=YES
                     // bususage=YES)
      // String neId = "1006119";    // KLNNMS02(cpuusage=YES cpu1min=YES memutil=YES
      // KLNNMS05(cpuusage=NO bususage=NO)

      Set<String> rras = new HashSet<String>();
      // klnnms02
      rras.add("cpu5sec");
      rras.add("cpu1min");
      rras.add("memutil");

      // klnnms05
      rras.add("cpuusage");
      rras.add("bususage");

      FetchLastCommandMessage message =
          CommandMessageFactory.createRRDLastCommandMessage(neId, "AVERAGE", 0, 0, null, rras);

      MessageProducer producer = null;
      MessageConsumer consumer = null;

      // time to send the JMS request
      try {
        TextMessage reqMsg, replyMsg;

        producer = session.createProducer(new HornetQQueue(SERVICE_QUEUE));

        // this will uniquelly identify the request
        String UIID = UUID.randomUUID().toString();

        reqMsg = session.createTextMessage();
        reqMsg.setStringProperty("ServiceRRD_msg_type", "fetchLast");
        reqMsg.setStringProperty("ServiceRRD_correlation_id", UIID);

        String body = JsonUtil.getInstance().toJSON(message);

        reqMsg.setText(body);

        logger.info("SEND:\n" + body);

        producer.send(reqMsg);

        consumer =
            session.createConsumer(
                new HornetQQueue(SERVICE_REPLY_QUEUE),
                "ServiceRRD_correlation_id = '" + UIID + "'");

        replyMsg = (TextMessage) consumer.receive(30000);

        if (replyMsg == null) {
          logger.info("ServiceRRD timeout on receive()");
        } else {
          logger.info("REPLY:\n" + replyMsg.getText());
        }

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          if (producer != null) producer.close();
          if (consumer != null) consumer.close();
        } catch (JMSException e) {
        }
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }