2015-11-03 51 views
1

我在Wildfly 8.2.0中有一個隊列,並且使用listener部署了ear。然後我試圖從客戶端程序發送文本消息到遠程隊列。在這種情況下,無法查找遠程連接工廠。附上程序和錯誤。無法從獨立的Java客戶端查找Wildfly 8.2.0的遠程連接工廠應用程序

MDB監聽器Wildfly

import javax.ejb.ActivationConfigProperty; 
import javax.ejb.MessageDriven; 
import javax.jms.JMSException; 
import javax.jms.Message; 
import javax.jms.MessageListener; 
import javax.jms.TextMessage; 

@MessageDriven(activationConfig = { 
     @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), 
     @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/mdbtest")}) 
public class ExampleQueueMDB implements MessageListener { 

    @Override 
    public void onMessage(Message message) { 
     if (message instanceof TextMessage) { 
      try { 
       System.out.println("----------------"); 
       System.out.println("Received: " 
         + ((TextMessage) message).getText()); 
       System.out.println("----------------"); 
      } catch (JMSException e) { 
       e.printStackTrace(); 
      } 
     } else { 
      System.out.println("----------------"); 
      System.out.println("Received: " + message); 
      System.out.println("----------------"); 
     } 
    } 

} 

Java客戶端程序

import java.util.logging.Logger; 
import java.util.Properties; 

import javax.jms.Connection; 
import javax.jms.ConnectionFactory; 
import javax.jms.Destination; 
import javax.jms.MessageConsumer; 
import javax.jms.MessageProducer; 
import javax.jms.Session; 
import javax.jms.TextMessage; 
import javax.naming.Context; 
import javax.naming.InitialContext; 

public class HelloWorldJMSClientSample { 
    private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName()); 

    // Set up all the default values 
    private static final String DEFAULT_MESSAGE = "Hello, World!"; 
    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory"; 
    private static final String DEFAULT_DESTINATION = "jms/queue/mdbtest"; 
    private static final String DEFAULT_MESSAGE_COUNT = "1"; 
    private static final String DEFAULT_USERNAME = "user"; 
    private static final String DEFAULT_PASSWORD = "pass"; 
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; 
    //private static final String PROVIDER_URL = "http-remoting://localhost:8080"; 
    private static final String PROVIDER_URL = "http-remoting://localhost:8080"; 

    public static void main(String[] args) throws Exception { 

     ConnectionFactory connectionFactory = null; 
     Connection connection = null; 
     Session session = null; 
     MessageProducer producer = null; 
     MessageConsumer consumer = null; 
     Destination destination = null; 
     TextMessage message = null; 
     Context context = null; 

     try { 
      // Set up the context for the JNDI lookup 
      final Properties env = new Properties(); 
      env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY); 
      env.put(Context.PROVIDER_URL, PROVIDER_URL); 
      env.put(Context.SECURITY_PRINCIPAL, DEFAULT_USERNAME); 
      env.put(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD); 

     env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
      context = new InitialContext(env); 

      // Perform the JNDI lookups 
      String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY); 
      log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\""); 
      connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString); 
      log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI"); 

      String destinationString = System.getProperty("destination", DEFAULT_DESTINATION); 
      log.info("Attempting to acquire destination \"" + destinationString + "\""); 
      destination = (Destination) context.lookup(destinationString); 
      log.info("Found destination \"" + destinationString + "\" in JNDI"); 

      // Create the JMS connection, session, producer, and consumer 
      connection = connectionFactory.createConnection(DEFAULT_USERNAME,DEFAULT_PASSWORD); 
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      producer = session.createProducer(destination); 
      // consumer = session.createConsumer(destination); 
      connection.start(); 

      int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT)); 
      String content = System.getProperty("message.content", DEFAULT_MESSAGE); 

      log.info("Sending " + count + " messages with content: " + content); 

      // Send the specified number of messages 
      for (int i = 0; i < count; i++) { 
       message = session.createTextMessage(content); 
       producer.send(message); 
      } 

     } catch (Exception e) { 
      log.severe(e.getMessage()); 
      throw e; 
     } finally { 
      if (context != null) { 
       context.close(); 
      } 

      // closing the connection takes care of the session, producer, and consumer 
      if (connection != null) { 
       connection.close(); 
      } 
     } 
    } 
} 

ERROR

SEVERE: Failed to create session factory 
Exception in thread "main" javax.jms.JMSException: Failed to create session factory 
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:615) 
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121) 
    at HelloWorldJMSClientSample.main(HelloWorldJMSClientSample.java:62) 
Caused by: java.lang.IllegalStateException: The following keys are invalid for configuring a connector: http-upgrade-endpoint, http-upgrade-enabled 
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.checkTransportKeys(ClientSessionFactoryImpl.java:1227) 
    at org.hornetq.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:181) 
    at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:589) 
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:611) 
    ... 2 more 

同時創造上線62連接,上面的錯誤來

connection = connectionFactory.createConnection(DEFAULT_USERNAME,DEFAULT_PASSWORD); 

我不確定,爲什麼這不起作用。希望這是一個簡單的例子。請讓我知道,如果有不同的方式來查找RemoteConnectionFactory。謝謝。

更新:

方法2: 如果我用下面的配置,能夠調用任何EJB方法,但仍然RemoteConnectionFactory查找拋出錯誤。

// Set up the context for the JNDI lookup 
final Properties env = new Properties(); 
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 
env.put("endpoint.name", "client-endpoint"); 
env.put("remote.connections","default"); 
env.put("remote.connection.default.port","8080"); 
env.put("remote.connection.default.host","localhost"); 
env.put("remote.connection.default.username", DEFAULT_USERNAME); 
env.put("remote.connection.default.password", DEFAULT_PASSWORD); 
env.put("org.jboss.ejb.client.scoped.context",true); 
context = new InitialContext(env); 

錯誤上述變更後,

INFO: Attempting to acquire connection factory "jms/RemoteConnectionFactory" 
SEVERE: Receive timed out 
Exception in thread "main" javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] 
    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1317) 
    at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1446) 
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594) 
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at HelloWorldJMSClientSample.main(HelloWorldJMSClientSample.java:56) 
Caused by: java.net.SocketTimeoutException: Receive timed out 
    at java.net.PlainDatagramSocketImpl.receive0(Native Method) 
    at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:146) 
    at java.net.DatagramSocket.receive(DatagramSocket.java:816) 
    at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1287) 
    ... 5 more 

錯誤來了查找,56行,

connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString); 

請提供這個問題的任何解決方案。謝謝。

回答

0

找到答案從https://developer.jboss.org/thread/265919

由於我使用的是infinispan,因此我使用了Wildfly 8.2.0的infinispan版本(6.0.2)作爲客戶端程序。但蜻蜓使用HornetQ 2.4.5和客戶端有HornetQ 2.2.7。我已經在客戶端更改爲HornetQ 2.4.5,並且一切正常。

相關問題