aspose file tools*
The moose likes JBoss/WildFly and the fly likes Help required for JMS on Jboss server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Help required for JMS on Jboss server" Watch "Help required for JMS on Jboss server" New topic
Author

Help required for JMS on Jboss server

Yogi Mehta
Greenhorn

Joined: Jun 24, 2009
Posts: 5

Hi All,

I am trying to create a simple JMS Queue program on Jboss Server. But I am getting follwing error. According to this error I am getting SpyQueue object and I am trying to cast it as Queue. Please suggest me what changes i need to do so that I will get Queue object instead of SpyQueue.

java.lang.ClassCastException: org.jboss.mq.SpyQueue
at com.ui.action.HelloG.mains(HelloG.java:27)
at com.ui.action.TestAction.process(TestAction.java:100)
at com.ui.BAction.execute(BAction.java:188)



Here is the Code that I am using. Please help me to get it resolved:

I have created one destination-service.xml file in deploy folder or JBoss app server:

<?xml version="1.0" encoding="UTF-8" ?>
<server>
<mbean code="org.jboss.mq.server.jmx.Queue"
name="jboss.mq.destination:service=Queue,name=queue0">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
</mbean>
</server>

Here is my class HelloG that is having all the logic:

package com.somthing.action;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;


public class HelloG
{
public void mains() throws Exception
{
// get the initial context
InitialContext ctx = new InitialContext();

// lookup the queue object
Queue queue = (Queue) ctx.lookup("queue/queue0");

// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.
lookup("queue/connectionFactory");

// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();

// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,
Session.DUPS_OK_ACKNOWLEDGE);

// create a queue sender
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.PERSISTENT);

// create a simple message to say "Hello"
TextMessage message = queueSession.createTextMessage("Hello");

// send the message
queueSender.send(message);

// print what we did
System.out.println("sent: " + message.getText());

// close the queue connection
queueConn.close();
}

/**
This method is called asynchronously by JMS when a message arrives
at the queue. Client applications must not throw any exceptions in
the onMessage method.
@param message A JMS message.
*/
public void onMessage(Message message)
{
TextMessage msg = (TextMessage) message;
try {
System.out.println("received: " + msg.getText());
} catch (JMSException ex) {
ex.printStackTrace();
}
}

}



Nilu Deshmukh
Greenhorn

Joined: Aug 03, 2009
Posts: 22
When I run the above code -- its give me following exception



what would be the problem ..
I wanted to run Simple JMS code...
but I think i am missing some settings...
I configured -service.xml and -ds.xml files..
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Nilu,

Please create a separate thread to discuss your issue, which is different what the original poster started this thread for. Also, in the new thread provide more details, including the version of JBoss and version of Java. Also provide relevant config files and any relevant code snippets.

[My Blog] [JavaRanch Journal]
Nilu Deshmukh
Greenhorn

Joined: Aug 03, 2009
Posts: 22
I Was a Issue of .jar files .
The Issue is resolved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help required for JMS on Jboss server