Dapr无法找到.NET Actor地址的问题排查求助
Dapr无法找到.NET Actor地址的问题排查与解决
问题描述
按照Dapr官方的.NET Actor教程运行时,客户端调用Actor方法时抛出error finding address for actor type MyActor with id 1错误,服务端日志显示Dapr已初始化完成,但存在PubSub组件连接错误。
环境信息
- Dapr CLI版本:1.9.1
- Dapr Runtime版本:1.9.3
Actor服务运行关键日志
PS D:\source\repos\Dapr.Actor.Example\MyActorService> dapr run --app-id myapp --app-port 5000 --dapr-http-port 3500 -- dotnet run # 省略无关日志片段 time="2022-11-19T10:05:06.6531356+01:00" level=info msg="actor runtime started. actor idle timeout: 1h0m0s. actor scan interval: 30s" app_id=myapp instance=XPS15-Cloud scope=dapr.runtime.actor type=log ver=1.9.3 time="2022-11-19T10:05:06.6827958+01:00" level=info msg="placement tables updated, version: 0" app_id=myapp instance=XPS15-Cloud scope=dapr.runtime.actor.internal.placement type=log ver=1.9.3 time="2022-11-19T10:05:08.8627382+01:00" level=error msg="error occurred while beginning pubsub pubsub: the server closed connection before returning the first response byte. Make sure the server returns 'Connection: close' response header before closing the connection" app_id=myapp instance=XPS15-Cloud scope=dapr.runtime type=log ver=1.9.3 time="2022-11-19T10:05:08.8633092+01:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 6062ms" app_id=myapp instance=XPS15-Cloud scope=dapr.runtime type=log ver=1.9.3
客户端调用错误日志
PS D:\source\repos\Dapr.Actor.Example\MyActorClient> dotnet run Startup up... Calling SetDataAsync on MyActor:1... Unhandled exception. Dapr.DaprApiException: error invoke actor method: error finding address for actor type MyActor with id 1 at Dapr.Actors.DaprHttpInteractor.SendAsyncHandleUnsuccessfulResponse(Func`1 requestFunc, String relativeUri, CancellationToken cancellationToken) at Dapr.Actors.DaprHttpInteractor.SendAsync(Func`1 requestFunc, String relativeUri, CancellationToken cancellationToken) at Dapr.Actors.DaprHttpInteractor.InvokeActorMethodWithRemotingAsync(ActorMessageSerializersManager serializersManager, IActorRequestMessage remotingRequestRequestMessage, CancellationToken cancellationToken) at Dapr.Actors.Communication.Client.ActorRemotingClient.InvokeAsync(IActorRequestMessage remotingRequestMessage, CancellationToken cancellationToken) at Dapr.Actors.Client.ActorProxy.InvokeMethodAsync(Int32 interfaceId, Int32 methodId, String methodName, IActorRequestMessageBody requestMsgBodyValue, CancellationToken cancellationToken) at Dapr.Actors.Client.ActorProxy.ContinueWithResult[TRetval](Int32 interfaceId, Int32 methodId, Task`1 task) at Program.<Main>$(String[] args) in D:\source\repos\Dapr.Actor.Example\MyActorClient\Program.cs:line 21 at Program.<Main>(String[] args)
排查与解决方案
1. 校验客户端配置匹配度
确保客户端指定了与服务端一致的Dapr端口和App ID:
- 客户端代码中需设置正确的Dapr HTTP端口(服务启动时的
--dapr-http-port 3500) - Actor代理创建时需关联正确的服务App ID(
myapp)
示例代码:
// 设置Dapr端口 Environment.SetEnvironmentVariable("DAPR_HTTP_PORT", "3500"); // 创建Actor代理,确保服务App ID正确 var actorProxy = ActorProxy.Create<IMyActor>(new ActorId("1"), "MyActor", new ActorProxyOptions { ActorServiceId = "myapp" });
2. 确认Actor服务注册正确性
检查服务端是否完成Actor类型注册和中间件配置:
// Program.cs中注册Actor builder.Services.AddActors(options => { options.Actors.RegisterActor<MyActor>(); }); // 配置Actor handlers app.MapActorsHandlers();
3. 验证Placement服务状态
Dapr Actor依赖Placement服务管理实例分布:
- 执行
dapr list查看placement服务是否运行 - 若未运行,手动启动:
dapr run --app-id placement --dapr-placement-port 50005 - 从日志
placement tables updated, version: 0来看,可能placement刚启动未完成初始化,等待1-2分钟后再重试调用
4. 检查网络可达性
- 测试客户端是否能访问Dapr HTTP端口:
Invoke-RestMethod -Uri http://localhost:3500/v1.0/actors/MyActor/1/method/GetDataAsync -Method Post
- 若请求失败,排查防火墙规则、端口占用情况
5. 隔离PubSub组件问题
日志中的PubSub错误是Redis连接异常,与Actor地址查找无关,可先注释掉PubSub组件配置,专注解决Actor问题,后续再处理Redis连接。
6. 重启Dapr与应用
停止所有Dapr进程后重新启动:
dapr stop --all dapr run --app-id myapp --app-port 5000 --dapr-http-port 3500 -- dotnet run
内容的提问来源于stack exchange,提问作者Lillvik
相关产品推荐
相关产品推荐

