[RESOLVIDO]JMS + JBOSS 4.2.2GA - javax.naming.NameNotFoundException: XAConnectionFactory not bound

1 resposta
S

Estou estudando JMS e me deparei com a seguinte exceção:

javax.naming.NameNotFoundException: XAConnectionFactory not bound
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
	at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
	at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
	at javax.naming.InitialContext.lookup(Unknown Source)
	at br.com.cliente.TesteJMS.teste(TesteJMS.java:39)
	at br.com.cliente.TesteJMS.main(TesteJMS.java:57)

Meu cliente JMS:
TesteJMS

package br.com.cliente;

import javax.ejb.Stateless;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.com.bean.Kyrostecnologia.ConsumidorBean;


public class TesteJMS{
	
	private Context ctx;
	/*A ConnectionFactory object encapsulates a set of connection configuration parameters that has been defined by an administrator.
	  A client uses it to create a connection with a JMS provider. */
	private QueueConnectionFactory cf;
	/* 
	 */
	private Connection conn;
	private Session session;
	private Queue fila;
	private MessageProducer messageProducer;
	private MessageConsumer messageConsumer;
	private TextMessage msg;
	private ConsumidorBean consumidorBean;
	
	public void teste(){
		try {
						
			ctx = new InitialContext();
			cf = (QueueConnectionFactory) ctx.lookup("java:/XAConnectionFactory"); // EXCEÇÃO LANÇADA AQUI
			conn = cf.createConnection();
			session = conn.createSession(true, 0);
			fila = (Queue) ctx.lookup("MyQueue");
			messageProducer = session.createProducer(fila);
			msg = session.createTextMessage("Congratulation, it works!");
			messageProducer.send(msg);
			
			conn.close();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (JMSException e) {
			e.printStackTrace();
		}
		
	}
	
	public static void main(String args[]){
		new TesteJMS().teste();
	}
}

Jndi.properties

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1100

No JBoss:
jms-ds.xml

<!-- The JMS provider loader -->
  <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
	 name="jboss.mq:service=JMSProviderLoader,name=JMSProvider">
    <attribute name="ProviderName">DefaultJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">
      org.jboss.jms.jndi.JNDIProviderAdapter
    </attribute>
    <!-- The combined connection factory -->
    <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>
   <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- Uncomment to use HAJNDI to access JMS
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
       java.naming.provider.url=localhost:1100
    </attribute>
    -->
  </mbean>

Agradeço por qualquer ajuda.
Auf Wiedersehen!!!

1 Resposta

S

RESOLVIDO:

na class TesteJMS:

try {  
                           
             ctx = new InitialContext();  
             cf = (QueueConnectionFactory) ctx.lookup("XAConnectionFactory");  
             conn = cf.createConnection();  
             session = conn.createSession(true, 0);  
             fila = (Queue) ctx.lookup("queue/MyQueue");  
             messageProducer = session.createProducer(fila);  
             msg = session.createTextMessage("Congratulation, it works!");  
             messageProducer.send(msg);  
               
             conn.close();  
         } catch (NamingException e) {  
             e.printStackTrace();  
         } catch (JMSException e) {  
             e.printStackTrace();  
         }
Criado 8 de julho de 2009
Ultima resposta 8 de jul. de 2009
Respostas 1
Participantes 1