4 Replies Latest reply on Aug 13, 2018 12:58 PM by jbertram

    JMSQueueControl countMessages() with filter not working


      Hi Guys,


      I've tried to search something on here and other places on the internet someone who has the same problem I do but I didn't find anybody so thats why I am opening this discussion. In short my problem is that the JMSQueueControl#countMessages doesn't work as I'd expect in case if I am using a filter.


      In more detail here is my case with some code snippet:

      I am using this queue to perform actions in the future so my messages are scheduled. To prevent a user submitting too much actions at once (I want to limit the number of active actions) and to calculate some numbers for the next action I came up with the idea to use the JMSQueueControl to count actually pending messages and prevent execution if the number exceeds the limit. I also using spring-test to write integration tests and preconfigured an embedded hornetQ to be able to test JMS functionality in my integration tests.


      Here is one of my non working code which submits JMS messages (not important parts are omitted)


      public void upgradeBuilding(Building building, Planet planet) throws NotEnoughResourcesException {
        planet = planetRepository.findOne(planet.getID());
        final String actorID = (planet.getOwner() != null) ? planet.getOwner().getID() : null;
        final int currLvl = planet.getBuildingLevel(building);
        try {
         int pending = (int) planetQueueControl.countMessages(String.format("planetID='%s' AND buildingName='%s'",
        final int nextLevel = currLvl + pending + 1;
        final long buildingTime = building.getBuildingTime(nextLevel);
        final Resources upgradeCost = building.getUpgradeCost(nextLevel);
         // Allocate resources
         // Queue action in the future
         UpgradeDowngradeBuildingAction action = new UpgradeDowngradeBuildingAction(planet.getID(),
        long executionTime = System.currentTimeMillis() + buildingTime;
        final Planet finalPlanet = planet;
         jmsTemplate.convertAndSend(JMS_DESTINATION, action, (msg) -> {
              if (actorID != null) {               
             msg.setStringProperty("actorID", actorID);     
             msg.setStringProperty("buildingName", building.getName());
              msg.setStringProperty("planetID", finalPlanet.getID());
              msg.setLongProperty("_HQ_SCHED_DELIVERY", executionTime);
             return msg;
         } catch (Exception e) {
         logger.error(e.getMessage(), e);


      Above when the code tries to count pending actions always gives back 0 when calling the method with a filter.

      Here is my integration test:


      public void testDoubleUpdateBuilding() throws Exception {
        Planet planet = getPlanet();
        String buildingName = "metalMine";
        planetService.upgradeBuilding(buildingName, planet.getID());
        planetService.upgradeBuilding(buildingName, planet.getID());
        long messages = planetQueueControl.countMessages(String.format("planetID='%s' AND buildingName='%s'", planet.getID(),
        Assert.assertEquals(2L, messages);


      This test always fails, but if I give null as selector, the method returns the number of messages in the queue. Another strange thing if I am calling listMessages(null) it gives back 0 messages as well while there are 2 messages in the queue.


      Here is my hornetq-configuration.xml

      <configuration xmlns="urn:hornetq"
        xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
        <connector name="in-vm">
        <param key="server-id" value="0"/>
        <acceptor name="in-vm">
        <param key="server-id" value="0"/>
        <address-setting match="#">



      <configuration xmlns="urn:hornetq"
        xsi:schemaLocation="urn:hornetq ../schemas/hornetq-jms.xsd ">
        <connection-factory name="ConnectionFactory">
        <connector-ref connector-name="in-vm"/>
        <entry name="ConnectionFactory"/>
        <queue name="DLQ">
        <entry name="/queue/DLQ"></entry>
        <queue name="ExpiryQueue">
        <entry name="/queue/ExpiryQueue"></entry>
        <queue name="planetQueue">
        <entry name="/queue/planetQueue"></entry>


      My first guess was transaction related but I've forbidden that one because why the non filtered method call gives back 2 while the filtered one gives back 0.  Has someone any idea why the count query gives back 0 messages when I am using it with a filter? Or Am I misconfigured something?