尝试发送JMS消息时出错

时间:2016-02-18 13:09:58

标签: java jms jndi

当我运行我的应用程序时,我有关于JNDI连接的错误。确切地说,错误发生在lookup上。这是代码:

   public static final String PROPERTIES_FILE = "jms-server"; //$NON-NLS-1$

   private static Logger logger = Logger.getLogger(JmsMessageProducer.class);

   private static final ResourceBundle res = ResourceBundle.getBundle(PROPERTIES_FILE);

   private static final String JBOSS_JNDI_PROVIDER_URL = res.getString("JBOSS_JNDI_PROVIDER_URL");

   private static final String JBOSS_JNDI_INITIAL_CONTEXT_FACTORY = res
         .getString("JBOSS_JNDI_INITIAL_CONTEXT_FACTORY");

   private static final String JBOSS_JMS_CONNECTION_FACTORY = res
         .getString("JBOSS_JMS_CONNECTION_FACTORY");

   private static final String JNDI_INPUT_JMS_QUEUE = res.getString("JNDI_INPUT_JMS_QUEUE");


   /**
    * Send JMS Text Message
    * 
    * @param myString
    */
   @SuppressWarnings({"unchecked", "rawtypes"})
   public void sendJmsTextMessage(String myString) {

      Context jndiContext = null;
      ConnectionFactory connectionFactory = null;
      Connection connection = null;
      Session session = null;
      Queue queue = null;
      MessageProducer messageProducer = null;

      try {
         // [1] Create a JNDI API InitialContext object.
         Hashtable properties = new Hashtable(2);
         properties.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_JNDI_INITIAL_CONTEXT_FACTORY);
         properties.put(Context.PROVIDER_URL, JBOSS_JNDI_PROVIDER_URL);
         logger.debug("Create Jndi Context with :" + Context.INITIAL_CONTEXT_FACTORY + "="
               + JBOSS_JNDI_INITIAL_CONTEXT_FACTORY + " " + Context.PROVIDER_URL + "="
               + JBOSS_JNDI_PROVIDER_URL);
         jndiContext = new InitialContext(properties);

         // [2] Look up connection factory and queue.
         logger.debug("Create connexion factory :" + JBOSS_JMS_CONNECTION_FACTORY);
         connectionFactory = (ConnectionFactory) jndiContext.lookup(JBOSS_JMS_CONNECTION_FACTORY);
         logger.debug("Create queue :" + JNDI_INPUT_JMS_QUEUE);
         queue = (Queue) jndiContext.lookup(JNDI_INPUT_JMS_QUEUE);

所以,他正在查看jms-server.properties文件:

JBOSS_JNDI_PROVIDER_URL = jnp://localhost:1199
JBOSS_JNDI_INITIAL_CONTEXT_FACTORY = org.jnp.interfaces.NamingContextFactory
JBOSS_JMS_CONNECTION_FACTORY = ConnectionFactory

JNDI_INPUT_JMS_QUEUE = queue/Incoming1JobsQueue

我得到的整个错误是:

  

12:36:35,198错误JmsMessageProducer:90 - 尝试发送JMS时出错   消息javax.naming.NameNotFoundException:Incoming1JobsQueue没有   界           at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)           at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)           at org.jnp.server.NamingServer.getObject(NamingServer.java:785)           在org.jnp.server.NamingServer.lookup(NamingServer.java:443)           at org.jnp.server.NamingServer.lookup(NamingServer.java:399)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl。   Java的:57)           at> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces   sorImpl.java:43)           at java.lang.reflect.Method.invoke(Method.java:606)           at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)           at sun.rmi.transport.Transport $ 2.run(Transport.java:202)           at sun.rmi.transport.Transport $ 2.run(Transport.java:199)           at java.security.AccessController.doPrivileged(Native Method)           at sun.rmi.transport.Transport.serviceCall(Transport.java:198)           at> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5   67)           at> sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run0(TCPTranspor)   t.java:828)           at> sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.access $ 400(TCPTr   ansport.java:619)           at> sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler $ 1.run(TCPTranspo   rt.java:684)           at> sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler $ 1.run(TCPTranspo   rt.java:681)           at java.security.AccessController.doPrivileged(Native Method)           at> sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run(TCPTransport)   的.java:681)           at> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。   Java的:1145)           at> java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor)   的.java:615)           在java.lang.Thread.run(Thread.java:745)           at> sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream   RemoteCall.java:275)           at> sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:   252)           at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)           at org.jnp.server.NamingServer_Stub.lookup(未知来源)           在org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728)           在org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)           在javax.naming.InitialContext.lookup(InitialContext.java:411)           at> fr.inra.grignon.persyst.web.jms.JmsMessageProducer.sendJmsTextMessage   (JmsMessageProducer.java:74)           at> fr.inra.grignon.persyst.web.servlet.DoResultats.doPost(DoResultats.ja   VA:407)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:650)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:731)           at> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl   icationFilterChain.java:303)           at> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF   ilterChain.java:208)           at> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52   )           at> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl   icationFilterChain.java:241)           at> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF   ilterChain.java:208)           at> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV   alve.java:220)           at> org.apache.catalina.core.StandardContextValve.invoke(StandardContextV   alve.java:122)           在org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)           at> org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica   torBase.java:505)           at> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j   AVA:170)           at> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j   AVA:103)           at> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:   957)           at> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal   ve.java:116)           at> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav)   一:423)           at> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp   11Processor.java:1079)           at> org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(   AbstractProtocol.java:620)           在org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoin)   t.java:316)           at> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor。   Java的:1145)           at> java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor)   的.java:615)           at> org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskTh   read.java:61)           在java.lang.Thread.run(Thread.java:745)

我出于某些原因使用JBoss和Tomcat(两者)。在JBoss jmx控制台中,我有:(我将其作为缩进图像插入)

enter image description here

我不知道问题的来源以及连接未绑定的原因。在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

如果你在JEE环境中运行,容器会期望一个JNDI名称,因为你希望容器管理资源而不是本机,所以为你感兴趣的队列创建一个JMS资源然后使用适当的JNDI名称来访问它,