File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes JMS Connect Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Connect Exception" Watch "JMS Connect Exception" New topic
Author

JMS Connect Exception

Nirmal Mukundan
Ranch Hand

Joined: Feb 21, 2007
Posts: 37

Hi

I have written a small JMS program. Its attached along. Here instead of configuring the JNDI, I have used
Sun System Message Queue ConnectionFactory. When I run the program as a standalone java program, I am getting the following
error. I am missing something over here. Is anything else required to be configured. I had got this program in the net.

Could some one help me in finding the issue.

Thanks


import javax.jms.ConnectionFactory;
import javax.jms.Connection;
import javax.jms.Session;
import javax.jms.MessageProducer;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.Message;
import javax.jms.TextMessage;

public class HelloWorldMessage {

/**
* Main method.
*
* @param args not used
*
*/
public static void main(String[] args) {

try {

ConnectionFactory myConnFactory;
Queue myQueue;


//Step 2:
//Instantiate a Sun Java(tm) System Message Queue ConnectionFactory
//administered object.
//This statement can be eliminated if the JNDI code above is used.
myConnFactory = new com.sun.messaging.ConnectionFactory();


//Step 3:
//Create a connection to the Sun Java(tm) System Message Queue Message
//Service.
Connection myConn = myConnFactory.createConnection();


//Step 4:
//Create a session within the connection.
Session mySess = myConn.createSession(false, Session.AUTO_ACKNOWLEDGE);


//Step 5:
//Instantiate a Sun Java(tm) System Message Queue Destination
//administered object.
//This statement can be eliminated if the JNDI code above is used.
myQueue = new com.sun.messaging.Queue("world");


//Step 6:
//Create a message producer.
MessageProducer myMsgProducer = mySess.createProducer(myQueue);


//Step 7:
//Create and send a message to the queue.
TextMessage myTextMsg = mySess.createTextMessage();
myTextMsg.setText("Hello World");
System.out.println("Sending Message: " + myTextMsg.getText());
myMsgProducer.send(myTextMsg);


//Step 8:
//Create a message consumer.
MessageConsumer myMsgConsumer = mySess.createConsumer(myQueue);


//Step 9:
//Start the Connection created in step 3.
myConn.start();


//Step 10:
//Receive a message from the queue.
Message msg = myMsgConsumer.receive();


//Step 11:
//Retreive the contents of the message.
if (msg instanceof TextMessage) {
TextMessage txtMsg = (TextMessage) msg;
System.out.println("Read Message: " + txtMsg.getText());
}


//Step 12:
//Close the session and connection resources.
mySess.close();
myConn.close();

} catch (Exception jmse) {
System.out.println("Exception occurred : " + jmse.toString());
jmse.printStackTrace();
}
}
}

Exception occurred : com.sun.messaging.jms.JMSException: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: java.net.ConnectException: Connection refused: connect
Dec 11, 2010 7:58:48 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler throwConnectionException
WARNING: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: java.net.ConnectException: Connection refused: connect
com.sun.messaging.jms.JMSException: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: java.net.ConnectException: Connection refused: connect
at com.sun.messaging.jmq.jmsclient.ExceptionHandler.throwConnectionException(ExceptionHandler.java:274)
at com.sun.messaging.jmq.jmsclient.ExceptionHandler.handleConnectException(ExceptionHandler.java:220)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.readBrokerPorts(PortMapperClient.java:241)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.init(PortMapperClient.java:150)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.<init>(PortMapperClient.java:84)
at com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPConnectionHandler.<init>(TCPConnectionHandler.java:124)
at com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler.openConnection(TCPStreamHandler.java:130)
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.openConnection(ConnectionInitiator.java:412)
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnectionOld(ConnectionInitiator.java:362)
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(ConnectionInitiator.java:210)
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(ConnectionInitiator.java:158)
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.init(ProtocolHandler.java:836)
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.<init>(ProtocolHandler.java:1528)
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.openConnection(ConnectionImpl.java:2366)
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.init(ConnectionImpl.java:1047)
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.<init>(ConnectionImpl.java:433)
at com.sun.messaging.jmq.jmsclient.UnifiedConnectionImpl.<init>(UnifiedConnectionImpl.java:60)
at com.sun.messaging.BasicConnectionFactory.createConnection(BasicConnectionFactory.java:147)
at com.sun.messaging.BasicConnectionFactory.createConnection(BasicConnectionFactory.java:132)
at com.test.jms.HelloWorldMessage.main(HelloWorldMessage.java:78)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.makeSocketWithTimeout(PortMapperClient.java:268)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.readBrokerPorts(PortMapperClient.java:220)
... 17 more
Rob Davies
author
Greenhorn

Joined: Nov 04, 2010
Posts: 6
It looks like the message broker isn't running - or isn't listening on locahost:7676.
Is the message broker already started ?

thanks,

Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMS Connect Exception