2017-10-08 323 views
0

我试图发送一些数据到Wildfly 10 Artemis实例并使用Apache Camel接收它们。 在这里,我知道,这可以使用camel-jms组件完成。发送数据到Wildfly 10嵌入的Artemis实例并接收它们使用Apache Camel

在这种情况下,我首先创建了一个简单的示例来检查这是否工作正常。 但是,它在ConnectionFactory创建点处给出了以下例外。

Exception in thread "main" javax.naming.NamingException: Failed to connect to any server. Servers tried: [http-remoting://localhost:8080] 
    at org.jboss.naming.remote.client.HaRemoteNamingStore.failOverSequence(HaRemoteNamingStore.java:213) 
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingStore(HaRemoteNamingStore.java:144) 
    at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:125) 
    at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:241) 
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79) 
    at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83) 
    at javax.naming.InitialContext.lookup(InitialContext.java:417) 

实现:

Properties props = new Properties(); 
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
props.put(Context.PROVIDER_URL, WILDFLY_REMOTING_URL); 
props.put(Context.SECURITY_PRINCIPAL, JMS_USERNAME); 
props.put(Context.SECURITY_CREDENTIALS, JMS_PASSWORD); 

InitialContext context = new InitialContext(props); 
ConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(JMS_CONNECTION_FACTORY_JNDI); 
System.out.println("connectionFactory : " + connectionFactory); 

SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder(); 
CamelContext ctx = new DefaultCamelContext(); 
ctx.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); 

ctx.addRoutes(routeBuilder); 
ctx.start(); 
Thread.sleep(5 * 60 * 1000); 
ctx.stop(); 

常量:

public final static String JMS_CONNECTION_FACTORY_JNDI="jms/RemoteConnectionFactory"; 
public final static String JMS_QUEUE_JNDI="jms/queue/TestQ"; 
public final static String JMS_USERNAME="jmsuser";  // The role for this user is "guest" in ApplicationRealm 
public final static String JMS_PASSWORD="[email protected]"; 
public final static String WILDFLY_REMOTING_URL="http-remoting://localhost:8080"; 

进口:

import java.util.Properties; 
import javax.jms.ConnectionFactory; 
import org.apache.camel.CamelContext; 
import org.apache.camel.component.jms.JmsComponent; 
import org.apache.camel.impl.DefaultCamelContext; 
import javax.jms.QueueConnectionFactory; 
import javax.naming.Context; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

但是,当我使用纯正的javax.jms(不是通过骆驼)时,会发生这种情况,如here中所述。当我直接发送消息给主动mq(而不是蜻蜓Artemis)时,它会成功运行。

SimpleRouteBuilder routeBuilder = new SimpleRouteBuilder(); 
CamelContext ctx = new DefaultCamelContext(); 

ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://0.0.0.0:61616"); 
ctx.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); 

ctx.addRoutes(routeBuilder); 
ctx.start(); 
Thread.sleep(5 * 60 * 1000); 
ctx.stop(); 

我想知道的是将数据发送到Wildfly嵌入式阿蒂米斯insnatnce和接收他们回来使用Apache骆驼。 有人可以提供一些小建议吗?

回答

2

您收到的错误是:

Failed to connect to any server. Servers tried: [http-remoting://localhost:8080] 

这表明,我认为你的Wildfly实例实际上并未听在localhost:8080 JNDI连接。你没有包含任何Wildfly配置或日志,所以这只是一个猜测。

此外,你还说过,“当我直接发送消息给主动mq(而不是蜻蜓Artemis)时,它可以成功运行”,但目前尚不清楚这实际上意味着什么。 Apache ActiveMQ Artemis(顾名思义)就是一个ActiveMQ代理,所以当你说你发送消息给“active mq”时,你是不是指独立的Artemis(即没有嵌入到Wildfly中)或ActiveMQ 5.x代理。

最后,称Artemis为“Wild Art Artemis”可能有点误导,因为Artemis不是Wildfly项目,而是Apache项目。我认为“蜻蜓Artemis”的意思是“蜻蜓嵌入的ActiveMQ Artemis”。

+0

@ Justin,谢谢你的回答。对于我的问题中不清楚的地方感到抱歉。在这种情况下,通过提及“active mq diretly”意味着发送给独立的ActiveMQ 5.x代理。是的,提到Wildfly Artemis,我将WildMly中的ActiveMQ Artemis包含在内。 – namalfernandolk

相关问题