【问题标题】:Apache-camel corda component connection error: Failed to create route route1Apache-camel corda组件连接错误:无法创建路由route1
【发布时间】:2019-09-14 03:50:25
【问题描述】:

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

Corda 运行正常。特别是,cardapp-example 正在运行,并且 Notary-PartyA - PartyB 和 PartyC 都处于活动状态。我可以使用他们的终端查询。 ActiveMQ 工作正常,我用另一个输入源对其进行了测试。 我还尝试连接所有四个节点的不同本地主机端口,以及骆驼的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");

我已经检查了这个问题Failed to create route route1,但没有任何帮助。 对于可能的原因,我将不胜感激。

【问题讨论】:

    标签: apache-camel corda


    【解决方案1】:

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

    您只需要配置一个Class 类型的bean 并将其提供给camel 注册中心。类似的东西应该可以工作(骆驼版本 2.24.x)

    import net.corda.core.contracts.OwnableState;
    import org.apache.camel.CamelContext;
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.impl.DefaultCamelContext;
    import org.apache.camel.impl.SimpleRegistry;
    
    public class CordaConnector {
    
        public static void main(String[] args) {
            try {
                SimpleRegistry registry = new SimpleRegistry();
                registry.put("contractStateClass", OwnableState.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();
            }
        }
    
    }
    

    编辑 for 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() 需要 HashMap, Object> 作为第二个参数。我应该在这里使用什么样的对象?
    • 嗨。也许你没有导入正确的类? SimpleRegistry 来自骆驼支持库扩展 LinkedHashMap ,所以 put(String, Object) 可用,请参阅 github.com/apache/camel/blob/master/core/camel-support/src/main/… 。请注意,这是一个简单的示例,如果您的项目使用 Spring,您可以简单地将 contractStateClass 注册为 Spring 应用程序上下文中的 Bean。我已经用使用过的导入更新了我的答案。
    • 再次感谢。你是对的,错误与导入的类有某种关系......因为,在我的导入中它无法解决:导入 org.apache.camel。 impl .SimpleRegistry ,但它只导入:import org.apache.camel。 支持。 SimpleRegistry 我使用的是 maven,最新版本是 3.0.0-RC1。你能告诉我你使用的是什么maven repo,版本吗?还是您正在使用其他来源?
    • 对不起我的错误:SimpleRegistry 是由camel-core 而不是camel-support 提供的,但我使用的是 Camel 版本 2.24.x(请参阅 github.com/apache/camel/blob/camel-2.24.x/camel-core/src/main/…,之前的链接是错误的)。似乎在 Camel 3.x 中进行了重构,并且此类在 camel-core 中不再可用
    • 我用一个基于 Camel v3.x 的工作示例更新了我的答案。你现在需要使用SimpleRegistry.bind() 方法; SimpleRegistry 已移至 camel-support 模块。请注意,您需要为contractStateClass 提供一个真实可用的类,在我的示例中,我使用了假类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 2018-02-14
    • 2019-05-06
    • 2015-04-06
    相关资源
    最近更新 更多