I have 2 simple EJB beans. The first one is a timer method that is called every second. In this method I add 10 random messages to a TestQueue.
@Singleton
@Startup
public class Timer {
@Inject
private JMSContext context;
@Resource(mappedName = "java:/jms/queue/TestQueue")
private Queue queue;
@Schedule(hour = "*", minute = "*", second = "*/1", persistent = false)
@AccessTimeout(unit = TimeUnit.DAYS, value = 1)
public void addToQueue() {
for(int i = 0; i<30; i++)
context.createProducer().send(queue, "msg " + (new Random().nextInt(100)));
printQueueSize();
}
public void printQueueSize() {
QueueBrowser qb = context.createBrowser(queue);
Enumeration enumeration = null;
try {
enumeration = qb.getEnumeration();
} catch (JMSException e) {
e.printStackTrace();
}
int size = 0;
while(enumeration.hasMoreElements()) {
enumeration.nextElement();
size++;
}
System.out.println("Queue size: " + size);
}
}
Second bean is a MDB consumer. I put Thread.sleep(100) to simulate long running task and make sure that there are some messages in TestQueue.
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/TestQueue"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")
})
public class Consumer implements MessageListener {
@Override
public void onMessage(Message msg) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
The problem is that console output shows:
15:06:29,006 INFO [stdout] (EJB default - 9) Queue size: 0
15:06:30,006 INFO [stdout] (EJB default - 10) Queue size: 0
15:06:31,009 INFO [stdout] (EJB default - 1) Queue size: 0
etc.
but in the wildfly admin console I can see that there are more and more messages every second:
The question is, why the QueueBrowser return empty Enumeration? Is it a bug in HornetQ implementation or there is some reason for that?
Aucun commentaire:
Enregistrer un commentaire