我正在尝试将一些数据发送到 Wildfly 10 Artemis 实例并使用 Apache Camel 接收它们。在这里,我知道,这可以使用 camel-jms 组件来完成。
在这种情况下,我首先创建了一个简单的示例来检查它是否工作正常。但它在 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="jmsuser@123";
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(不是通过 Camel)时,这种情况会成功发生。当我直接向活动 mq(而不是 Wildfly 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 嵌入式 Artemis insnatnce 发送数据并使用 Apache Camel接收它们。任何人都可以对此提供一点提示吗?