Hi,
Using 4.0.1 on Linux.
I'm trying to consume some messages from a set of queues that I've defined.
Queue 1, 2, 3 and 4
These are created by a factory that instantiates 4 instances of a class,
passing in the name of the queue that the instantiated class should monitor.
However, nothing is coming off the queue and I can see in the JMX console
that I have about 1,900 messages waiting for me to pickup...
Here's my code:
First the producer:
private void doIt() throws Exception {
final Context context = new InitialContext(getContextProperties());
final QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
final Queue queue =
(Queue)context.lookup("dynamicQueues/queryQueue");
final QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
final QueueSession queueSession =
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final QueueSender queueSender = queueSession.createSender(queue);
final TextMessage textMessage = queueSession.createTextMessage();
queueConnection.start();
for(int i = 0 ; i < 10 ; i++) {
textMessage.setText("Hello World! " + i);
System.out.println("Sending message with text : " +
textMessage.getText());
queueSender.send(textMessage);
}
queueSender.send(queueSession.createMessage());
queueConnection.close();
}
private Properties getContextProperties() {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put(Context.PROVIDER_URL,
"tcp://jmsserver:61616?jms.useAsyncSend=true");
return properties;
}
}
Now the consumer:
private void bootstrap() {
try {
final Context context = new InitialContext(getContext());
final QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
final Queue queue = (Queue) context.lookup(getQueueName());
final QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
final QueueSession queueSession =
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSession.createReceiver(queue);
queueSession.setMessageListener(this);
queueConnection.start();
System.out.println("Started " + getName() + " on queue " +
queue.getQueueName());
} catch(Exception e) {
logger.error(e);
}
}
public String getName() {
return name;
}
public String getQueueName() {
return queueName;
}
public void onMessage(final Message message) {
try {
if(message instanceof ObjectMessage) {
final LoggingEvent loggingEvent = (LoggingEvent)
((ObjectMessage) message).getObject();
Logger.getLogger(loggingEvent.getLoggerName()).info(loggingEvent.getRenderedMessage());
} else if(message instanceof TextMessage) {
final String payload = ((TextMessage) message).getText();
System.out.println(payload);
logger.info(payload);
}
} catch(JMSException e) {
logger.error(e);
}
}
private Properties getContext() {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://jmsserver:61616");
return properties;
}
Any help would be very very much appreciated!
-=david=-
--
View this message in context:
http://www.nabble.com/Can%27t-get-messages-off-the-queue%21-tf2158965.html#a5965055
Sent from the ActiveMQ - User forum at Nabble.com.