java - 使用 Apache Camel 将数据发送到 Wildfly 10 嵌入式 Artemis 实例并接收它们

标签 java apache-camel jms wildfly-10 activemq-artemis

我正在尝试将一些数据发送到 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)时,这种情况会成功发生,如 here 中所述。 。当我直接向 Activity 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 接收它们。 有人可以就此提供一些建议吗?

最佳答案

您收到的错误是:

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

这向我表明您的 Wildfly 实例实际上并未在 localhost:8080 上监听 JNDI 连接。您尚未包含任何 Wildfly 配置或日志记录,因此这只是一个猜测。

您还说过,“当我直接向 Activity mq(而不是 Wildfly Artemis)发送消息时,它会成功运行”,但尚不清楚这实际上意味着什么。 Apache ActiveMQ Artemis(顾名思义)是一个 ActiveMQ 代理,因此当您说您将消息发送到“active mq”时,不清楚您是指独立的 Artemis(即未嵌入 Wildfly)还是 ActiveMQ 5.x 代理。

最后,将 Artemis 称为“Wildfly Artemis”可能会有点误导,因为 Artemis 不是 Wildfly 项目,而是 Apache 项目。我认为“Wildfly Artemis”实际上是指“嵌入 Wildfly 中的 ActiveMQ Artemis”。

关于java - 使用 Apache Camel 将数据发送到 Wildfly 10 嵌入式 Artemis 实例并接收它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46632422/

相关文章:

java - RecyclerView.Adapter 中的 getRef(position).getKey()

Java httpclient 4.1 如何发送带有可配置端口的post请求

jms - Apache Camel : consuming a file after a direct

java - Camel AQ 路由错误 TypeConversionException at Xpath

javax.jms.MessageListener : What additional threading concerns to take care of?

java - Glassfish 和 JMS : Why do published messages not arrive at subscribers?

java - 出处——Java错误: Cannot find symbol

java - 将 jar 文件添加到 NetBeans Maven 中的依赖项

java - 在apachecamel中聚合后生成多个文件

jms - 延迟消息队列最佳实践