为什么在 Akka.net 中以 class 的形式发送消息是一个好习惯?
why is it a good practice to send Messages in the form of a class in Akka.net?
我是 Akka.net 的新手,我在 Akka.net bootcamp 阅读本教程,它说你可以将任何类型的练习将消息封装在 class 中,例如:
Actor 1 想要请求 Actor 2 拥有的信息(为了简单起见,假设一个整数),根据我从训练营中了解到的情况,Actor 2 必须以下列方式响应
Actor2: ReceiveActor{
int info =5;
public Actor2(){
Recieve<Request>(request => sender.Tell(new Response(this.info));
}
public class Response
{
int Info {get;}
public Response(int info){
Info = info;
}
}
}
为什么这是一个好习惯?
这是因为所有消息都必须是不可变的,所以 class with private setter 可以帮助您实现不可变,因为您只在构造时设置所有属性值。 Akka 需要不可变消息来保证路由或分片等操作。
我是 Akka.net 的新手,我在 Akka.net bootcamp 阅读本教程,它说你可以将任何类型的练习将消息封装在 class 中,例如:
Actor 1 想要请求 Actor 2 拥有的信息(为了简单起见,假设一个整数),根据我从训练营中了解到的情况,Actor 2 必须以下列方式响应
Actor2: ReceiveActor{
int info =5;
public Actor2(){
Recieve<Request>(request => sender.Tell(new Response(this.info));
}
public class Response
{
int Info {get;}
public Response(int info){
Info = info;
}
}
}
为什么这是一个好习惯?
这是因为所有消息都必须是不可变的,所以 class with private setter 可以帮助您实现不可变,因为您只在构造时设置所有属性值。 Akka 需要不可变消息来保证路由或分片等操作。