Apache camel Apache组件连接错误:无法创建路由route1

Apache camel Apache组件连接错误:无法创建路由route1,apache-camel,corda,Apache Camel,Corda,我正在尝试使用该组件连接到Corda,并再次使用ApacheCamel的Corda组件将数据发送到ApacheActiveMQ 科尔达运转正常。特别是,cardapp示例正在运行,并且公证人-PartyA-PartyB和PartyC还活着。我可以使用他们的终端进行查询。 ActiveMQ工作正常,我用另一个输入源测试它。 我还尝试连接所有四个节点的不同本地主机端口,以及Camel的corda组件网页中显示的示例 public class CordaConnector { public v

我正在尝试使用该组件连接到Corda,并再次使用ApacheCamel的Corda组件将数据发送到ApacheActiveMQ

科尔达运转正常。特别是,cardapp示例正在运行,并且公证人-PartyA-PartyB和PartyC还活着。我可以使用他们的终端进行查询。 ActiveMQ工作正常,我用另一个输入源测试它。 我还尝试连接所有四个节点的不同本地主机端口,以及Camel的corda组件网页中显示的示例

public class CordaConnector {
    public void ConnectToCorda() throws Exception {
        CamelContext context = new DefaultCamelContext();
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass").
            }
        });

        while(true) {
            context.start();
        }
    }
}
我收到以下错误消息:

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[corda://localhost:10004?username=user1&pa... because of Failed to resolve endpoint: corda://localhost:10004?contractStateClass=%23contractStateClass&operation=VAULT_TRACK&password=test&username=user1 due to: Error binding property (contractStateClass=#contractStateClass) with name: contractStateClass on bean: org.apache.camel.component.corda.CordaConfiguration@1de76cc7 with value: #contractStateClass
...
因此,单独测试时,corda工作正常,ActiveMQ工作正常(具有不同的输出),我尝试了不同的端口来查询信息。我已尝试使用不同的命令进行查询,例如:

from("corda://localhost:10000?username=user1&password=test&operation=NETWORK_MAP_FEED").
to("activemq:queue:try");
我检查了这个问题,但没有帮助。
如果您能提供任何帮助,我将不胜感激。

在您的路由
from
uri中,您正在使用value
#contractStateClass
设置
contractStateClass
属性:这引用了Camel注册表中名为
contractStateClass
的bean。但是,由于您没有在上下文注册表中绑定任何具有此名称的bean,Camel无法解析此值:
错误绑定属性(contractStateClass=#contractStateClass),该属性的名称为:在bean上的contractStateClass:org.apache.Camel.component.corda。CordaConfiguration@1de76cc7带值:#contractStateClass

您只需配置
Class
类型的bean并将其提供给camel注册表。类似的东西应该可以使用(camel版本2.24.x)

为Camel v3.x编辑

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.SimpleRegistry;

public class CordaConnector {

    public static void main(String[] args) {
        try {
            SimpleRegistry registry = new SimpleRegistry();
            registry.bind("contractStateClass", MyContractClass.class);
            CamelContext camelContext = new DefaultCamelContext(registry);
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass")
                            .log("got message");
                }
            });
            camelContext.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

但这并没有解决问题。首先,我遇到了编译错误,它通知registry.Put()需要HashMapHi。可能您没有导入正确的类LinkedHashMap,因此
put(String,Object)
可用,请参阅。请注意,这是一个简单的例子,如果您的项目使用Spring,您可以简单地在Spring应用程序上下文中将
contractStateClass
注册为Bean。我已经用使用过的导入更新了我的答案。再次感谢。您是对的,错误与导入的类有关。。。因为,在我的导入中,它无法解析:import org.apache.camel。SimpleRegistry,但它只导入:import org.apache.camel。支持。SimpleRegistry我使用的是maven,最新版本是3.0.0-RC1。你能告诉我你用的是什么maven repo版本吗?或者您正在使用另一个源代码?对不起,我的错误是:
SimpleRegistry
camel-core
提供,而不是
camel-support
,但我使用的是camel版本2.24.x(请参阅,前面的链接是错误的)。重构似乎是在Camel 3.x中完成的,这个类在Camel coreI中不再可用。我用一个基于Camel v3.x的工作示例更新了我的答案。现在需要使用
SimpleRegistry.bind()
方法
SimpleRegistry
已移动到
camel support
模块。请注意,您需要为
contractStateClass
提供一个真正可用的类,在我的示例中,我使用了fake类。
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.SimpleRegistry;

public class CordaConnector {

    public static void main(String[] args) {
        try {
            SimpleRegistry registry = new SimpleRegistry();
            registry.bind("contractStateClass", MyContractClass.class);
            CamelContext camelContext = new DefaultCamelContext(registry);
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass")
                            .log("got message");
                }
            });
            camelContext.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}