This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JMS Connect Exception" Watch "JMS Connect Exception" New topic

JMS Connect Exception

Nirmal Mukundan
Ranch Hand

Joined: Feb 21, 2007
Posts: 37


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.


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
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());

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

//Step 9:
//Start the Connection created in step 3.

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

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

Exception occurred : com.sun.messaging.jms.JMSException: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: 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: Connection refused: connect
com.sun.messaging.jms.JMSException: [C4003]: Error occurred on connection creation [localhost:7676]. - cause: Connection refused: connect
at com.sun.messaging.jmq.jmsclient.ExceptionHandler.throwConnectionException(
at com.sun.messaging.jmq.jmsclient.ExceptionHandler.handleConnectException(
at com.sun.messaging.jmq.jmsclient.PortMapperClient.readBrokerPorts(
at com.sun.messaging.jmq.jmsclient.PortMapperClient.init(
at com.sun.messaging.jmq.jmsclient.PortMapperClient.<init>(
at com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPConnectionHandler.<init>(
at com.sun.messaging.jmq.jmsclient.protocol.tcp.TCPStreamHandler.openConnection(
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.openConnection(
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnectionOld(
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(
at com.sun.messaging.jmq.jmsclient.ConnectionInitiator.createConnection(
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.init(
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.<init>(
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.openConnection(
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.init(
at com.sun.messaging.jmq.jmsclient.ConnectionImpl.<init>(
at com.sun.messaging.jmq.jmsclient.UnifiedConnectionImpl.<init>(
at com.sun.messaging.BasicConnectionFactory.createConnection(
at com.sun.messaging.BasicConnectionFactory.createConnection(
at com.test.jms.HelloWorldMessage.main(
Caused by: Connection refused: connect
at Method)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at<init>(Unknown Source)
at<init>(Unknown Source)
at com.sun.messaging.jmq.jmsclient.PortMapperClient.makeSocketWithTimeout(
at com.sun.messaging.jmq.jmsclient.PortMapperClient.readBrokerPorts(
... 17 more
Rob Davies

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 ?


I agree. Here's the link:
subject: JMS Connect Exception
It's not a secret anymore!