I am writing JMS Code for the first time: Writen Clent side coding :
package com.Serviceclient;
import java.util.HashMap;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
import com.ibm.websphere.wim.model.Context;
public class Main
{
public static void main(
String[] args) throws JMSException
{
System.setProperty("javax.net.ssl.keyStore","c://Program Files/IBM/WebSphere/AppServer/java/src.zip/java/security//keystore/myKeystore.jks");
System.setProperty("javax.net.ssl.keyStorePassword","password");
System.setProperty("javax.net.ssl.keyStoreType","jks");
System.setProperty("com.ibm.ssl.performURLHostNameVerification", "true");
Hashtable<String, String> props = new Hashtable<String, String>();
QueueConnection connection = null;
QueueSender sender = null;
QueueSession session = null;
props.put(javax.naming.Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
try {
InitialContext context = new InitialContext(props);
Queue q=(Queue)context.lookup("jms/messageQueue");
QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("jms/messageQueueCF");
System.out.println(q);
connection = factory.createQueueConnection();
session = connection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
connection.start();
sender = session.createSender(q);
//create and set a message to send
TextMessage msg = session.createTextMessage();
for (int i = 0; i < 5; i++) {
System.out.println("Factory-->");
msg.setText("This is my sent message " + (i + 1));
sender.send(msg);
}
connection.stop();
connection.close();
session.close();
}
catch (NamingException e) {
e.printStackTrace();
}
}
}
AND to receive the message sent from Client side I wrote other code as :
package com.sample.mdb;
import java.util.StringTokenizer;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
/**
* Message-Driven Bean implementation class for: MQServiceRequest
*
*/
/*@MessageDriven(
activationConfig = { @ActivationConfigProperty(
propertyName = "destinationType", propertyValue = "javax.jms.Queue"
) },
mappedName = "jms/messageQueue")*/
@MessageDriven(activationConfig = { @ActivationConfigProperty(
propertyName = "destinationType", propertyValue = "javax.jms.Queue"
),@ActivationConfigProperty(propertyName = "destination",
propertyValue = "jms/messageQueue") })
public class MQServiceRequest implements MessageListener {
/**
* Default constructor.
*/
public MQServiceRequest() {
// TODO Auto-generated constructor stub
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
// TODO Auto-generated method stub
TextMessage msg = null;
//MessageConsumer myConsumer = mySession.createConsumer(myDest);
//MyMessageListener myListener = new MyMessageListener();
//got the message msg1 which we will change as String msgs with "" as token and now we will break it into Email and command and use it as per the requirement
try {
TextMessage aMsg = null;
TextMessage msg1 = (TextMessage) aMsg;
String msgs=msg1.getText();
StringTokenizer st = new StringTokenizer(msgs);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
System.out.println("Got Message:" + msg1.getText());
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable te) {
te.printStackTrace();
}
}
}
But when I am running the main class no output message is sended to queue or received so how the process will go for MDB ?
I am getting Output and no message getting recieved ------> Feb 4, 2012 9:52:42 PM null null
WARNING: WSVR0072W
Feb 4, 2012 9:52:43 PM null null
WARNING: WSVR0072W
Feb 4, 2012 9:52:43 PM null null
WARNING: WSVR0072W
Feb 4, 2012 9:52:43 PM null null
WARNING: WSVR0072W
Factory-->com.ibm.ws.sib.api.jms.impl.JmsQueueConnectionFactoryImpl@871ff81
queue://MDBQueue?busName=MDBSIBus
Please help me out.....