-
1. Re: JMS Client not able to pull any messages from the Queue
dannyyates Jun 15, 2004 4:46 AM (in response to brightsunny2020)Have you read the JMS spec? Have you read about "delivery modes"?
-
2. Re: JMS Client not able to pull any messages from the Queue
brightsunny2020 Jun 16, 2004 11:08 AM (in response to brightsunny2020)
Thanks dannyyates
Yes, I read JMS Spec
and I set the delivery mode to PERSISTENT also
Thanks
Sunny -
3. Re: JMS Client not able to pull any messages from the Queue
dannyyates Jun 16, 2004 11:22 AM (in response to brightsunny2020)OK. I assume it still doesn't work? Are you setting the PERSISTENT property CORRECTLY? I vaguely recall there are two ways to do it. What works for me (although it appears to contradict the Javadoc for QueueSender) is to set the property on the Message immediatly before calling QueueSender.send()
Otherwise, are you persisting your messages to MySQL? I think there was a bug in a recent version of JBoss whereby the SQL for manipulating the MySQL JMS tables was wrong, and wouldn't reload messages on startup (or something like that).
Try upgrading to the latest version, and/or try persisting to a different database.
Failing that, start showing some code... -
4. Re: JMS Client not able to pull any messages from the Queue
brightsunny2020 Jun 17, 2004 3:02 PM (in response to brightsunny2020)Thanks dannyyates
I tried by seting the persistence mode to message, didn't work. Then I tried setting the persistence mode for both QueuSender and Message, still no luck
Can u pls. take a look at the code or Please copy&paste ur code here that works for you. I am using to the file system persistence
public class SimpleQueueSender {
/**
* Main method.
*
* @param args the queue used by the example and,
* optionally, the number of messages to send
*/
public static void main(String[] args) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS;
// Initial context strings
String PROVIDER_URL = "java.naming.provider.url";
String NAMING_FACTORY = "java.naming.factory.initial";
String CONTEXT_FACTORY =
"org.jnp.interfaces.NamingContextFactory";
String jndiHost = "localhost:1099";
NUM_MSGS = 5;
queueName = "queue/orafin/OrafinServices";
Properties props = new Properties();
props.put(NAMING_FACTORY, CONTEXT_FACTORY);
props.put(PROVIDER_URL, jndiHost);
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext(props);
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("ConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create sender and text message.
* Send messages, varying text slightly.
* Send end-of-messages message.
* Finally, close connection.
*/
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.PERSISTENT);
message = queueSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " +
message.getText());
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
queueSender.send(message);
}
/*
* Send a non-text control message indicating end of
* messages.
*/
queueSender.send(queueSession.createMessage());
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
}
import javax.jms.*;
import javax.naming.*;
import java.util.*;
public class SimpleQueueReceiver {
/**
* Main method.
*
* @param args the queue used by the example
*/
public static void main(String[] args) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;
// Initial context strings
String PROVIDER_URL = "java.naming.provider.url";
String NAMING_FACTORY = "java.naming.factory.initial";
String CONTEXT_FACTORY =
"org.jnp.interfaces.NamingContextFactory";
String jndiHost = "localhost:1099";
queueName = "queue/orafin/OrafinServices";
Properties props = new Properties();
props.put(NAMING_FACTORY, CONTEXT_FACTORY);
props.put(PROVIDER_URL, jndiHost);
System.out.println("Queue name is " + queueName);
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext(props);
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("ConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create receiver, then start message delivery.
* Receive all text messages from queue until
* a non-text message is received indicating end of
* message stream.
* Close connection.
*/
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
Message m = queueReceiver.receive(1);
while (m != null) {
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
message.getText());
}
}
m = queueReceiver.receive(1);
}
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
}