【问题标题】:Sending data to a Wildfly 10 embedded Artemis instance and receive them back USING Apache Camel使用 Apache Camel 将数据发送到 Wildfly 10 嵌入式 Artemis 实例并接收它们
【发布时间】:2018-03-19 20:02:40
【问题描述】:

我正在尝试将一些数据发送到 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;

但是当我使用here 中提到的纯 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 实例发送数据并接收它们使用 Apache Camel。 有人可以给点建议吗?

【问题讨论】:

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


    【解决方案1】:

    您收到的错误是:

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

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

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

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

    【讨论】:

    • @贾斯汀,谢谢你的回答。对于我的问题中不清楚的领域,我深表歉意。在这种情况下,直接提及“active mq”意味着发送到独立的 ActiveMQ 5.x 代理。是的,提到 Wildfly Artemis,我的意思是嵌入在 Wildfly 中的 ActiveMQ Artemis。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 2022-11-18
    • 2017-07-29
    相关资源
    最近更新 更多