2014-11-21 1 views
1

Я очень новичок в Apache Camel и совершенно новый для Spring. Я пытаюсь отправить JMS-сообщения во встроенный hornetq в Wildfly (ver.8.1.0). Вот мой код:Поиск верблюда RemoteConnectionFactory на Wildfly

public class CamelJMS { 

public static void main(String[] args) throws Exception { 
    try { 
     CamelContext cc = new DefaultCamelContext(); 

     Properties prop = new Properties(); 
     prop.put(Context.INITIAL_CONTEXT_FACTORY, 
     "org.jboss.naming.remote.client.InitialContextFactory"); 
     prop.put(Context.URL_PKG_PREFIXES, 
     "org.jboss.jms.jndi.JNDIProviderAdapter"); 
     prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
     prop.put(Context.SECURITY_PRINCIPAL, 
     System.getProperty("username", "usr")); 
     prop.put(Context.SECURITY_CREDENTIALS, 
     System.getProperty("password", "pwd")); 

     JndiTemplate jndiT = new JndiTemplate(prop); 
     jndiT.bind("ccf", "jms/RemoteConnectionFactory"); 
     JndiObjectFactoryBean jndiCFB = new JndiObjectFactoryBean(); 
     jndiCFB.setJndiTemplate(jndiT); 
     JmsComponent jmsC = JmsComponent.jmsComponent((ConnectionFactory)jndiCFB.getObject()); 

     cc.addComponent("jmsrc", jmsC); 
     cc.addRoutes(new RouteBuilder() { 
      @Override 
      public void configure() throws Exception { 
       System.out.println("Go!"); 
       onException(Throwable.class) 
       .handled(true) 
       .process(new Processor() { 
        @Override 
        public void process(Exchange arg0) throws Exception { 
         System.out.println("error."); 
         ((Exception) arg0.getProperty("CamelExceptionCaught", Exception.class)).printStackTrace(); 
        } 
       }); 
       from("file:///Users/Foo/Desktop/IN") 
       .process(new Processor() { 
        @Override 
        public void process(Exchange arg0) throws Exception { 
         System.out.println(arg0.getIn().getHeader("CamelFileAbsolutePath", String.class)); 
         System.out.println(arg0.getIn().getBody(String.class)); 
        } 
       }) 
       .to("jms:jms/generatoreQueue?connectionFactory=ccf"); 
      } 
     }); 

     cc.start(); 
     Thread.sleep(10000); 
     cc.stop(); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

}

Я уверен, что конфигурация моего Wildfly, потому что я могу получить доступ к той же очереди используется не клиент верблюд. Когда я запускаю мой клиент, я получил эту ошибку:

org.jboss.naming.remote.protocol.NamingIOException: Failed to bind [Root exception is java.io.IOException: Internal server error.] 
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49) 
at org.jboss.naming.remote.protocol.v1.Protocol$2.execute(Protocol.java:220) 
at org.jboss.naming.remote.protocol.v1.Protocol$2.execute(Protocol.java:179) 
at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.bind(RemoteNamingStoreV1.java:108) 
at org.jboss.naming.remote.client.HaRemoteNamingStore$2.operation(HaRemoteNamingStore.java:288) 
at org.jboss.naming.remote.client.HaRemoteNamingStore$2.operation(HaRemoteNamingStore.java:285) 
at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137) 
at org.jboss.naming.remote.client.HaRemoteNamingStore.bind(HaRemoteNamingStore.java:284) 
at org.jboss.naming.remote.client.RemoteContext.bind(RemoteContext.java:133) 
at org.jboss.naming.remote.client.RemoteContext.bind(RemoteContext.java:137) 
at javax.naming.InitialContext.bind(InitialContext.java:419) 
at org.springframework.jndi.JndiTemplate$2.doInContext(JndiTemplate.java:198) 
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
at org.springframework.jndi.JndiTemplate.bind(JndiTemplate.java:196) 
at edu.pezzati.camel.jms.broker.CamelJMSBroker.main(CamelJMSBroker.java:38) 
Caused by: java.io.IOException: Internal server error. 
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:82) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:744) 

Глядя в журнал сервера, я нашел это:

... 
09:12:02,585 INFO [org.jboss.as.naming] (default task-5) JBAS011806: Channel end notification received, closing channel Channel ID 793d9f9e (inbound) of Remoting c 
onnection 4406e6f5 to /127.0.0.1:49289 
09:12:20,121 ERROR [org.jboss.as.naming] (pool-1-thread-1) JBAS011807: Unexpected  internal error: java.lang.UnsupportedOperationException: JBAS011859: Naming context is read-only 
    at org.jboss.as.naming.WritableServiceBasedNamingStore.requireOwner(WritableServiceBasedNamingStore.java:161) 
    at org.jboss.as.naming.WritableServiceBasedNamingStore.bind(WritableServiceBasedNamingStore.java:66) 
    at org.jboss.as.naming.NamingContext.bind(NamingContext.java:253) 
    at org.jboss.naming.remote.protocol.v1.Protocol$2.handleServerMessage(Protocol.java:249) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45] 
    at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45] 
... 

Конечно, я что-то неправильно настроенной весны JndiTemplate, но я не могу понять вне какой.

ответ

1

Я не знаком с Wildfly и немного знаком с JBoss, но вы сказали, что параметры конфигурации должны быть правильными. Так основаны от моего опыта настраиваемой Верблюжьего JmsComponent ...

Попробуйте это:

 Properties prop = new Properties(); 
    prop.put(Context.INITIAL_CONTEXT_FACTORY, 
    "org.jboss.naming.remote.client.InitialContextFactory"); 
    prop.put(Context.URL_PKG_PREFIXES, 
    "org.jboss.jms.jndi.JNDIProviderAdapter"); 
    prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
    prop.put(Context.SECURITY_PRINCIPAL, 
    System.getProperty("username", "usr")); 
    prop.put(Context.SECURITY_CREDENTIALS, 
    System.getProperty("password", "pwd")); 

    Context context = new InitialContext(prop); 
    ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory"); 

    JmsComponent jmsC = new JmsComponent(connectionFactory); 

    cc.addComponent("jms", jmsC); 

и изменить конечную точку:

 .to("jms:queue:generatoreQueue"); 

Вы не нужны "JMS /" перед именем очереди, а имя компонента должно совпадать с тем, что вы связали с ним выше в методе addComponent.

+0

Здравствуйте, рад снова вас слышать! Просто, чтобы заставить весь материал работать, я изменил строку '.to (" jms: queue: generatoreQueue ");' in '.to (" jms: queue: generatoreQueue? Username = usr & password = pwd ");'. Еще раз спасибо. – Francesco