2017-10-08 317 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

相關問題