It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes How to receive message after sending from client side ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to receive message after sending from client side ?" Watch "How to receive message after sending from client side ?" New topic
Author

How to receive message after sending from client side ?

roma pradhan
Greenhorn

Joined: Feb 04, 2012
Posts: 1

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.....



Mainak Goswami
Ranch Hand

Joined: May 21, 2006
Posts: 50


Hi Roma,

I feel you need to check the JMS server configuration and administered objects. Can you please share the configuration details for administered objects?


------------------------------------
Mainak
idiotechie
------------------------------------
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to receive message after sending from client side ?
 
Similar Threads
Error while using MDB with JMS
com.ibm.ejs.container.EJBConfigurationException: NO_JCA_ADAPTER_BINDING found for MDB: ConsumerTest
.SAR file problem
MDB onMessage not invoked
annotations for JNDI lookup