Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to receive message after sending from client side ?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



 
Ranch Hand
Posts: 52
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic