我试图发送一些数据到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骆驼。 有人可以提供一些小建议吗?
@ Justin,谢谢你的回答。对于我的问题中不清楚的地方感到抱歉。在这种情况下,通过提及“active mq diretly”意味着发送给独立的ActiveMQ 5.x代理。是的,提到Wildfly Artemis,我将WildMly中的ActiveMQ Artemis包含在内。 – namalfernandolk