I\'m trying to connect to an ActiveMQ broker using AMQP 1.0, but I want to use JMS within my application code. I\'m interested in using JMS primarily because I want developers t
it is better to work with jndi
public static void main(String[] args) throws JMSException, InterruptedException, NamingException {
Connection connection = null;
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
props.setProperty("connectionfactory.myFactoryLookup",
"amqp://localhost:5672");
props.put("topic." + "MyTOPIC", "customerTopic");
InitialContext ic = new InitialContext(props);
ConnectionFactory cf1 = (ConnectionFactory) ic.lookup("myFactoryLookup");
Topic topic = (Topic) ic.lookup("MyTOPIC");
connection = cf1.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
connection.start();
for (int i = 0; i < 10; i++) {
Message msg = session.createTextMessage("Task : " + i);
producer.send(msg);
}
session.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
replace
org.apache.qpid
qpid-amqp-1-0-client-jms
0.32
by
org.apache.qpid
qpid-jms-client
0.9.0
on the broker side you need to add:
ref http://activemq.apache.org/amqp.html