Apache-camel corda component connection error: Failed to create route route1

Apache-camel corda component connection error: Failed to create route route1

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

Corda 运行 正确。特别地,cardapp-example 是 运行,并且 Notary-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 中,您正在使用值 #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();
        }
    }

}

编辑 骆驼 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();
        }
    }
}