I'm new to JMS , and I'm trying to load a connectionFactory. I followed a couple of tutorials , but for some reason it doesn't seem to work , I get an exception every time I try to '.lookup' connectionfactory. I'm using JBoss7.1.
Here is the class from where I'm trying to get the connectionFactory:
public class QueueSend extends Frame implements ActionListener {
private QueueConnectionFactory qconFactory;
private QueueConnection qcon;
private QueueSession qsession;
private QueueSender qsender;
private Queue queue;
private TextMessage msg;
private TextField tf=new TextField();
private Button send=new Button("Send");
public QueueSend(){
super("Queue Sender");
setLocation(150,50);
setSize(200,100);
add(tf);
add(send,BorderLayout.SOUTH);
send.addActionListener(this);
send.setEnabled(false);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent w){
send("quit");
close();
System.exit(0);
}
});
setVisible(true);
init();
}
public void init(){
try{
InitialContext ctx = getInitialContext();
qconFactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
queue = (Queue) ctx.lookup("java:/queue/text");
qcon = qconFactory.createQueueConnection();
qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
qsender = qsession.createSender(queue);
qcon.start();
send.setEnabled(true);
}catch(NamingException e1){e1.printStackTrace();
}catch(JMSException e2){e2.printStackTrace();}
}
public void actionPerformed(ActionEvent e){
String message=tf.getText();
tf.setText("");
if(message.length()>0)
send(message);
}
public void send(String message){
try{
//send a message with the given string
TextMessage textMessage = qsession.createTextMessage(message);
qsender.send(textMessage);
// enter text here
}catch(JMSException e){e.printStackTrace();}
}
public void close(){
try{
qsender.close();
qsession.close();
qcon.close();
}catch(JMSException e1){e1.printStackTrace();
}catch(NullPointerException e2){e2.printStackTrace();}
}
public static void main(String[] args){
new QueueSend();
}
public InitialContext getInitialContext(){
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
properties.put("java.naming.provider.url","remote://127.0.0.1:4447");
properties.put("jboss.naming.client.ejb.context","true");
properties.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false" );
try {
return new InitialContext(properties);
} catch (NamingException e) {
System.out.println("Cannot generate InitialContext");
e.printStackTrace();
}
return null;
}
}
I get this exception:
javax.naming.NameNotFoundException: ConnectionFactory -- service jboss.naming.context.java.jboss.exported.ConnectionFactory
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.j ava:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
When i log into JBoss server from the browser , I can't find 'ConnectionFactory' under the 'naming' tab
this is from the standalone-full.xml:
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="RemoteConnectionFactory"/>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
What am i doing wrong ?
I found out what the problem was. The default configuration file for my JBoss server was standalone.xml while the connectionFactory is configured in the standalone-full.xml file which is a more full version of the standalone.xml, So all I had to do was change the configuration file of the server from standalone.xml to standalone-full.xml and that did the trick :@)~
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With