如何在Akka.NET的Akka.Delivery中获取对远程ProducerController的引用?

huangapple go评论59阅读模式
英文:

How to get reference to remote ProducerController in Akka.NET's Akka.Delivery?

问题

我正在尝试使用Akka.Delivery在本地生产者进程和远程消费者进程之间实现精确一次交付。根据这篇文章,我需要将消费者控制器注册到生产者控制器。我已经配置了两个项目并正确设置了一切。然而,我在注册过程中遇到了问题。

以下是文章中的代码块:

private IActorRef CreateConsumerController()
{
    var consumerControllerSettings = ConsumerController.Settings.Create(Context.System);
    var consumerControllerProps = ConsumerController.Create<IMessageProtocol>(Context, Option<IActorRef>.None, consumerControllerSettings);
    var consumerController = Context.ActorOf(consumerControllerProps, "consumer-controller");

    consumerController.Tell(new ConsumerController.Start<IMessageProtocol>(Self));
    consumerController.Tell(new ConsumerController.RegisterToProducerController<IMessageProtocol>(_producerController));

    return consumerController;
}

我需要帮助确保生产者控制器与消费者控制器正确注册,或者反之。如何实际获取到位于远程进程中的producerController的引用。

英文:

I am attempting to implement exactly-once delivery using Akka.Delivery between a local producer process and a remote consumer process. According to this article, I need to register the consumer controller with the producer controller. I have configured both projects and set everything up correctly. However, I am having issues with the registration process.

Here is the code block from the article:

private IActorRef CreateConsumerController()
{
    var consumerControllerSettings = ConsumerController.Settings.Create(Context.System);
    var consumerControllerProps = ConsumerController.Create<IMessageProtocol>(Context, Option<IActorRef>.None, consumerControllerSettings);
    var consumerController = Context.ActorOf(consumerControllerProps, "consumer-controller");

    consumerController.Tell(new ConsumerController.Start<IMessageProtocol>(Self));
    consumerController.Tell(new ConsumerController.RegisterToProducerController<IMessageProtocol>(_producerController));

    return consumerController;
}

I need help ensuring that the producer controller is properly registered with the consumer controller, or vice versa. How to actually get reference to producerController which is in remote process.

答案1

得分: 1

你需要首先在生产者和消费者之间建立一个Akka.Remote连接,以便获取对ProducerController的引用。

在Akka.Cluster中,您可以通过形成一个集群然后构建一个ActorSelectionProducerController来实现这一点:

var pcPath = "/user/producerController"; // 将此替换为您的ProducerController在层次结构中的位置
IActorRef producerControllerReference = await myActorSystem.ActorSelection(remoteMember.Address + pcPath).ResolveOne(CancellationToken.None);

^^ 我是凭记忆打的这段代码,所以不要指望它可以编译,但基本是正确的。

如果您不使用Akka.Cluster,您需要手动提供一个Address,可以是Address对象或字符串形式,并运行完全相同类型的代码。

英文:

You'll need to establish an Akka.Remote connection between the producer and consumer first in order to get a reference to the ProducerController.

In Akka.Cluster you could do this by just forming a cluster together and then constructing an ActorSelection to the ProducerController:

var pcPath = "/user/producerController"; // replace this with wherever your ProducerController is in the hierarchy
IActorRef producerControllerReference = await myActorSystem.ActorSelection(remoteMember.Address + pcPath).ResolveOne(CancellationToken.None);

^^ I'm typing this from memory so don't expect that to compile, but that's generally right.

If you're not using Akka.Cluster, you'll need to manually provide an Address in either Address or string form and run the exact same type of code.

huangapple
  • 本文由 发表于 2023年6月16日 13:09:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76487104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定