Hi All,
I am new to ActiveMQ. I have to write a consumer for activeMQ queue.
ActiveMQ brokers already setup by other team.
When i am trying to connect to broker using tcp it stuck at line
connection.start().
Java control doesnt go beyond this line. I never recieved an
exception/error.. it seems its waiting for connection.
Belwo is teh simple code i am using. As i havent setup ActiveMQ, i am just
trying to recieve messge from a queue. I do not have setup info of activeMQ,
is there some setting required at ActiveMQ setup end.
Note:- ActiveMq setup are on different server i am runnning cosumer on my
local. So it is connection over teh network.
Code:-
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
public class ActiveMQTest {
private static String brokerURL =
"failover://(tcp://rpc1044.daytonoh.ncr.com:61616?trace=true)";
private static transient ConnectionFactory factory;
private transient Connection connection;
private transient Session session;
private String jobs[] = new String[]{"suspend", "delete"};
public ActiveMQTest() throws JMSException {
factory = new ActiveMQConnectionFactory(brokerURL);
System.out.println("------");
connection = factory.createConnection();
System.out.println("1");
connection.start();
System.out.println("2");
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
}
public void close() throws JMSException {
if (connection != null) {
connection.close();
}
}
public static void main(String[] args) throws JMSException {
ActiveMQTest consumer = new ActiveMQTest();
for (String job : consumer.jobs) {
Destination destination =
consumer.getSession().createQueue("JOBS." +
job);
MessageConsumer messageConsumer =
consumer.getSession().createConsumer(destination);
messageConsumer.setMessageListener(new Listener(job));
}
}
public Session getSession() {
return session;
}
}
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
public class Listener implements MessageListener {
private String job;
public Listener(String job) {
this.job = job;
}
public void onMessage(Message message) {
try {
//do something here
System.out.println(job + " id:" +
((ObjectMessage)message).getObject());
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
It never prints "2" in logs. it stuck at line connection.start().
Any help would be appreciated. Thanks!
Reagrds
Archana
--
View this message in context:
http://activemq.2283324.n4.nabble.com/Not-able-to-start-connection-with-ActiveMQ-broker-from-a-network-client-tp3232550p3232550.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.