Exception:
ConnectionFactory is ::: org.apache.activemq.ActiveMQConnectionFactory
javax.jms.JMSException: Could not connect to broker URL: tcp://PDCHCL-TRAX9:61616. Reason: java.net.ConnectException: Connection refused: connect
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:278)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:222)
at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:185)
at com.test.IROPSQueueApacheMQProducer.main(IROPSQueueApacheMQProducer.java:58)
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 org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:414)
at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:380)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:50)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:258)
... 3 more
This is the very first exception I got when I started to code my first JMS code. Due to wrong Listener Connection (IN red and green (my mistake of taking 9))
package oc.messageQ.olivia;
import java.io.File;
import java.io.FileInputStream;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class IROPSQueueApacheMQProducer {
/**
* @author O Cassandrae
* @param args
*/
public static void main(String[] args) {
MessageProducer producer = null;
Connection conn = null;
Session jmsSession = null;
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
//env.put(Context.PROVIDER_URL,"tcp://PDCHCL-TRAX9:61616");
env.put(Context.PROVIDER_URL,"tcp://PDCHCL-TRAX6:61616");
InitialContext context = new InitialContext(env);
ConnectionFactory cf = (ConnectionFactory) context
.lookup("ConnectionFactory");
System.out.println("ConnectionFactory is ::: "
+ cf.getClass().getName());
if (cf instanceof QueueConnectionFactory) {
conn = ((QueueConnectionFactory) cf).createQueueConnection();
jmsSession = ((QueueConnection) conn).createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
}
Destination dest = (Destination) context
.lookup("dynamicQueues/GROUNDOPS.PSCS.IROPS.BRIDGE.QUEUE");
System.out.println("dest is ::: " + dest);
producer = ((QueueSession)jmsSession).createSender((Queue)dest);
TextMessage message = jmsSession.createTextMessage();
String AsmSource = "src/resources/IROPSFlightCancelled.xml";
FileInputStream inputStream;
byte[] readBytes;
// build an asm request
inputStream = new FileInputStream(AsmSource);
readBytes = new byte[Integer.valueOf(""+(new File(AsmSource)).length())];
inputStream.read(readBytes);
message.setText(new String(readBytes));
//System.out.println("request: "+new String(readBytes));
((QueueSender)producer).send(message);
//System.out.println("Message sent successfully!!!");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(conn != null){
producer.close();
jmsSession.close();
conn.close();
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ConnectionFactory is ::: org.apache.activemq.ActiveMQConnectionFactory
javax.jms.JMSException: Could not connect to broker URL: tcp://PDCHCL-TRAX9:61616. Reason: java.net.ConnectException: Connection refused: connect
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:278)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:222)
at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:185)
at com.test.IROPSQueueApacheMQProducer.main(IROPSQueueApacheMQProducer.java:58)
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 org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:414)
at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:380)
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:50)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:57)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:258)
... 3 more
This is the very first exception I got when I started to code my first JMS code. Due to wrong Listener Connection (IN red and green (my mistake of taking 9))
package oc.messageQ.olivia;
import java.io.File;
import java.io.FileInputStream;
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class IROPSQueueApacheMQProducer {
/**
* @author O Cassandrae
* @param args
*/
public static void main(String[] args) {
MessageProducer producer = null;
Connection conn = null;
Session jmsSession = null;
try {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
//env.put(Context.PROVIDER_URL,"tcp://PDCHCL-TRAX9:61616");
env.put(Context.PROVIDER_URL,"tcp://PDCHCL-TRAX6:61616");
InitialContext context = new InitialContext(env);
ConnectionFactory cf = (ConnectionFactory) context
.lookup("ConnectionFactory");
System.out.println("ConnectionFactory is ::: "
+ cf.getClass().getName());
if (cf instanceof QueueConnectionFactory) {
conn = ((QueueConnectionFactory) cf).createQueueConnection();
jmsSession = ((QueueConnection) conn).createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
}
Destination dest = (Destination) context
.lookup("dynamicQueues/GROUNDOPS.PSCS.IROPS.BRIDGE.QUEUE");
System.out.println("dest is ::: " + dest);
producer = ((QueueSession)jmsSession).createSender((Queue)dest);
TextMessage message = jmsSession.createTextMessage();
String AsmSource = "src/resources/IROPSFlightCancelled.xml";
FileInputStream inputStream;
byte[] readBytes;
// build an asm request
inputStream = new FileInputStream(AsmSource);
readBytes = new byte[Integer.valueOf(""+(new File(AsmSource)).length())];
inputStream.read(readBytes);
message.setText(new String(readBytes));
//System.out.println("request: "+new String(readBytes));
((QueueSender)producer).send(message);
//System.out.println("Message sent successfully!!!");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(conn != null){
producer.close();
jmsSession.close();
conn.close();
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Please do start the bat file: C:\Software\apache-activemq-5.5.1\bin\activemq.bat (activemq.bat) before executing the program.
No comments:
Post a Comment