java - The method createConnection() is undefined for the the class ConnectionFactory -
i have been trying learn activemq , jms. when compile following code above exception. although, have attached right jar files jms , activemq. eclipse asks me add cast connectionfactory object when try create connection (i.e. connectionfactory.createconnection()) using connectionfactory object. codes see everywhere on internet same have written.
import javax.jms.connection; import javax.jms.connectionfactory; import javax.jms.deliverymode; import javax.jms.destination; import javax.jms.messageproducer; import javax.jms.session; import javax.jms.textmessage; import org.apache.activemq.activemqconnection; import org.apache.activemq.activemqconnectionfactory; public class jmsproducer { public static void main(string[] args) { try { // create connectionfactory connectionfactory connectionfactory=new activemqconnectionfactory("admin", "admin", activemqconnection.default_broker_url); // create connection connection connection = connectionfactory.createconnection(); //error seen in above line connection.start(); // create session session session = connection.createsession(false, session.auto_acknowledge); // create destination destination destination = session.createqueue("testq"); // create messageproducer session queue messageproducer producer = session.createproducer(destination); producer.setdeliverymode(deliverymode.non_persistent); // create messages textmessage message = session.createtextmessage("helloworld"); producer.send(message); session.close(); connection.close(); system.out.println("message sent"); } catch (exception e) { system.out.println(e); e.printstacktrace(); } } }
sholud have done activemqconnection connection = connectionfactory.createconnection(); instead of connection connection = connectionfactory.createconnection();. code running fine.
Comments
Post a Comment