访问akka-camel actor下的Camel / Jetty实例

我有一个基本的Jetty实例使用带akka和scala的akka-camel库 . 例如:

class RestActor extends Actor with Consumer {
    def endpointUri = "jetty:https://0.0.0.0:443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

我想将SslSocketConnector绑定到底层的jetty实例,以便我可以加载我的SSL证书,但我遇到的问题是我无法弄清楚如何处理底层jetty实例来调用addConnector()函数 . 我有一个想法是将Camel特性添加到我的类中(例如:RestActor使用Consumer with Camel扩展Actor)来访问Camel的“context”变量,但编译器抱怨这样做会覆盖“context”变量,该变量也存在于阿卡的演员特质 .

回答(1)

2 years ago

以下代码似乎提供对底层Camel对象的访问 .

class RestActor extends Actor with Consumer {
    val camel = CamelExtension(context.system).context
    def endpointUri = "jetty:https://0.0.0.0:443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}

编辑:我包括使用akka的scala akka-camel库成功运行Jetty w / SSL的最终代码,适用于寻找未来如何实现这一点的示例的任何人 .

class RestActor extends Actor with Consumer {

    val ksp: KeyStoreParameters = new KeyStoreParameters();
    ksp.setResource("/path/to/keystore");
    ksp.setPassword("...");
    val kmp: KeyManagersParameters = new KeyManagersParameters();
    kmp.setKeyStore(ksp);
    val scp: SSLContextParameters = new SSLContextParameters();
    scp.setKeyManagers(kmp);
    val jettyComponent: JettyHttpComponent = CamelExtension(context.system).context.getComponent("jetty", classOf[JettyHttpComponent])
    jettyComponent.setSslContextParameters(scp);

    def endpointUri = "jetty:https://0.0.0.0:8443/"
    def receive = {
        case msg: CamelMessage => {
            ...
        }
        ...
    }
    ...
}