-
1. Re: JMS queue created with @JMSDestinationDefinition doesn't show-up in Admin Console nor CLI
jmesnil Jul 9, 2014 6:31 AM (in response to davidj)Currently, the Web console does not allow to manage deployed JMS resources (tracked by https://issues.jboss.org/browse/HAL-334).
In the mean time, the alternative is to use the CLI console to manage them (under /deployment=XXX/subsystem=messaging/...)
-
2. Re: JMS queue created with @JMSDestinationDefinition doesn't show-up in Admin Console nor CLI
davidj Jul 9, 2014 12:58 PM (in response to jmesnil)Thanks Jeff. Following your instructions I did find my queue in the CLI. Thanks. As a side question (maybe I should create a new ticket), but I'm only able to receive one message. For example suppose I send two messages to the queue. The first message will be "Message 1". The second message will be "Message 2". Then, if I receive a message from the queue, I will get "Message 1". Then I attempt to receive another message, instead of receiving "Message 2", I get "null". If I shutdown the server and restart, and receive a message then I will get "Message 2". Do you know why I'm only able to pop one message total.
My code is very simple: To send a message I do this:
context.createProducer().send(queue, message);
To receive a message I do:
String received = context.createConsumer(queue).receiveBody(String.class);
Thanks,
David
-
3. Re: JMS queue created with @JMSDestinationDefinition doesn't show-up in Admin Console nor CLI
davidj Jul 9, 2014 6:59 PM (in response to davidj)I figured-out why only one "receive()" could be made. The reason is because I needed to "close()" the JMSConsumer.
For example, I was doing this:
String received = context.createConsumer(queue).receiveBody(String.class);
But the "createConsumer()" method needs to be closed either explicitly or using the try-autoclose feature of Java. For example:
try(JMSConsumer consumer = context.createConsumer(queue)) {
String received = consumer.receiveBody(String.class, 5000);
}
Now it works fine.
Thanks.
-
4. Re: JMS queue created with @JMSDestinationDefinition doesn't show-up in Admin Console nor CLI
jmesnil Jul 11, 2014 8:09 AM (in response to davidj)It may not be intuitive but once a consumer is created, it will automatically start receiving messages and HornetQ will deliver them to the client
So in your case, the 1st consumer was receiving the messages from WildFly.
When you created the 2nd consumer, there was no messages in the queue since both messages where being delivered to the consumer. You saw the 1st one when you call receive but there was a 2nd one that was in its buffer.
When you close a consumer, the undelivered messages in its buffer go back to the queue so that other consumers can receive them.
I don't recommend to use context.createConsumer(queue).receive... type of code since it is easy to forget that the created consumer will still exist after the code is executed and continue to receive messages. It's better to keep a reference on the JMSConsumer.
Does that makes sense?
-
5. Re: JMS queue created with @JMSDestinationDefinition doesn't show-up in Admin Console nor CLI
davidj Jul 11, 2014 1:08 PM (in response to jmesnil)That makes sense. I noticed that behavior when I created a MessageDrivenBean on the same Queue. There was something like 7 messages in the Queue and once I deployed the MDB with a break point it stopped 7 times (one for each message).
Can you provide me with a quick code example of what you mean by "It's better to keep a reference on the JMSConsumer".
Thanks.
Also, as a follow-up question, if I use the old-fashion way of getting a JMSContext (thru JNDI) I do this:
InitialContext ic = new InitialContext();
ConnectionFactory factory = (ConnectionFactory) ic.lookup("/ConnectionFactory");
Queue queue = (Queue) ic.lookup("global/jms/Q1"); // ----> WHY DO I DO THIS WHEN THE ACTUAL QUEUE NAME IS "java:global/jms/Q1"?
try(JMSContext context = factory.createContext()) {
context.createProducer().send(queue, "Hello World");
}
The name of the queue is: java:global/jms/Q1
I know that JBoss often times doesn't require the prefix, but that assumes everything will be "java:". Yet notice how the "lookup()" used "/ConnectionFactory" yet I don't think it's full name is "java:/ConnectionFactory". Also, when using @Resource you need to use the "java:". This seems like a potential place for confusion.
Thanks.