-
1. Re: Sending Entities in Messages?
smokingapipe Dec 23, 2006 12:21 AM (in response to smokingapipe)Ok, wait, I just discovered something: the ObjectMessage. I can use that on any class which can be serialized. Fortunately my message classes are very simple things and can be serialized easily.
But.... this is all running within one JVM. Is JBoss smart enough to know not to serialize these objects, but to just clone them or whatever? I assume it must know this. This is an important performance thing. -
2. Re: Sending Entities in Messages?
smokingapipe Dec 28, 2006 4:44 AM (in response to smokingapipe)I realize that JBoss/MQ is dead because JBoss Messaging is going to replace it in the upcoming JBoss 5. Are there any good quick-start guides for doing this simple thing? In a regular Java program, I would create a worker thread, but obviously in an enterprise environment, we don't want to create threads. Instead we send messages. I'm just trying to get a very simple example working, of a servlet sending a message to a MDB within the same EAR.
-
3. Re: Sending Entities in Messages?
byorn Dec 28, 2006 5:15 AM (in response to smokingapipe)//use this send the object to the queue
public class SendMessagesViaMDB{
//method to get the queue connection
public static javax.jms.QueueConnection getQueueConnection( java.util.Hashtable environment ) throws javax.naming.NamingException, javax.jms.JMSException
{
// Obtain initial context
javax.naming.InitialContext initialContext = new javax.naming.InitialContext(environment);
try {
java.lang.Object objRef = initialContext.lookup(CONNECTION_FACTORY_JNDI_NAME);
return ((javax.jms.QueueConnectionFactory) objRef).createQueueConnection();
} finally {
initialContext.close();
}
}
/**
* TO BE CALLED IN THE CLIENT SIDE
* @param STUFF
*/
public void sendSTUFFViaMDB(Collection STUFF) {
QueueConnection queueConnection = null;
QueueSession jmsSession = null;
try {
queueConnection = getTravelAgentMailingServiceMDBQueueConnection();
jmsSession = queueConnection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = jmsSession.createSender(getQueueConnection(JNDI PROPS));
// create the message and set the content
ObjectMessage message = jmsSession.createObjectMessage();
message.setObject((ArrayList) STUFF)
//send the message
sender.send(message);
sender.close();
log.debug("Message is written to jms queue");
} catch (JMSException e) {
log.error("Sending message via jms failed", e);
} catch (NamingException e) {
log.error("Sending message via jms failed",e);
} catch(ModuleException moduleException) {
log.error("Sending message via jms failed", moduleException);
} finally {
if (queueConnection != null){
try {
queueConnection.close();
} catch (JMSException e) {
log.error("Closing jms queue connection failed", e);
}
}
if (jmsSession != null){
try {
jmsSession.close();
} catch (JMSException e) {
log.error("Closing jms session failed", e);
}
}
}
}
//THE MDB
public class MessagingServiceMDB implements MessageDrivenBean, MessageListener {
public void onMessage(Message message){
try {
ObjectMessage objMessage = (ObjectMessage)message;
ArrayList msgProfiles = (ArrayList)objMessage.getObject();
MyMessageManager manager = new MyMessageManager ();
manager.processMessages(msgProfiles);
} catch (JMSException jmsException) {
+ jmsException.getMessage(), jmsException);
} catch (Exception exception) {
+ exception.getMessage(), exception);
}
} -
4. Re: Sending Entities in Messages?
smokingapipe Dec 28, 2006 6:35 PM (in response to smokingapipe)I have all this set up, and I'm getting:
javax.naming.NameNotFoundException: TestQueue not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at org.jnp.server.NamingServer.lookup(NamingServer.java:270) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) at javax.naming.InitialContext.lookup(InitialContext.java:392) etc
Here's my MDB:@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination",propertyValue="queue/TestQueue") }) public class TestMDB implements MessageListener {
which should create teh TestQueue, right?
Any ideas on this? As with all things JBoss, getting the configuration right is half the battle.
Thanks -
5. Re: Sending Entities in Messages?
smokingapipe Dec 28, 2006 6:52 PM (in response to smokingapipe)I just now looked at the JMX console and I didn't see my queue/TestQueue anywhere in it, so obviously JBoss isn't registering that MDB. Hmmm.
-
6. Re: Sending Entities in Messages?
smokingapipe Dec 28, 2006 7:57 PM (in response to smokingapipe)Ah, never mind that one. My MDB wasn't in my beans jar, and even JBoss isn't psychic, so...