c# - 由于 RpcException DeadlineExceeded,无法从 Lambda 将事件附加到 EventStoreDb
问题描述
我在 C# 中有一个带有 netcoreapp3.1 的简单 AWS lambda,它尝试使用 gRPC 客户端 ( EventStore.Client.Grpc.Streams
) 将一些事件附加到 EventStoreDb 中的流中。
在本地,(在 AWS Lambda 之外)我可以针对我的远程 EventStoreDb 正确使用相同的功能。当部署为 AWS Lambda 时,我得到了异常
{
"errorType": "RpcException",
"errorMessage": "Status(StatusCode=DeadlineExceeded, Detail=\"\")",
"stackTrace": [
"at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncClientStreamingCall>b__5_0[TRequest,TResponse](Task`1 t)",
"at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()",
"at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)",
"at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)",
"at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)",
"--- End of stack trace from previous location where exception was thrown ---",
"at EventStore.Client.EventStoreClient.AppendToStreamInternal(AppendReq header, IEnumerable`1 eventData, EventStoreClientOperationOptions operationOptions, UserCredentials userCredentials, CancellationToken cancellationToken)",
"at EventStoreDb.LambdaSample.EventStore.Append(String streamName, Int32 aggregateVersion, IEnumerable`1 events, CancellationToken cancellationToken) in /mnt/c/src/issue-lambda-eventstore/src/EventStoreDb.LambdaSample/EventStore.cs:line 25",
"at EventStoreDb.LambdaSample.LambdaEntryPoint.FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context) in /mnt/c/src/issue-lambda-eventstore/src/EventStoreDb.LambdaSample/LambdaEntryPoint.cs:line 52",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
]
}
该问题可以重现,我在此处添加了代码:https ://gitlab.com/sunnyatticsoftware/sandbox/issue-lambda-eventstore 以及有关如何使用 AWS CLI 部署/运行 lambda 函数的说明。
请注意,说明所指的角色的 ARN 可能与您的情况不同,并且它使用 my--profile diegosasw
您必须在您自己的 AWS CLI 中进行修改
代码在 repo 中,但作为总结,这是失败的简单函数
public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
{
context.Logger.LogLine("Get Request\n");
context.Logger.LogLine("Storing sample events in event store");
var eventStoreClient = EventStoreClientFactory.Create(ConnectionString);
var serializationService = new SerializationService(SupportedTypes.Default);
var eventStore = new global::EventStoreDb.LambdaSample.EventStore(eventStoreClient, serializationService);
var foo = new Foo("First event");
var bar = new Bar( "Second event");
var events = new List<object> {foo, bar};
var id = Guid.NewGuid();
var streamName = $"SampleLambda-{id}";
// this is my own wrapper function
await eventStore.Append(streamName, events.Count, events, CancellationToken.None);
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = "Events persisted successfully",
Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
};
return response;
}
更新:我也在这里创建了它:https ://discuss.eventstore.com/t/grpc-core-rpcexception-deadlineexceeded-in-aws-lambda/3174
解决方案
推荐阅读
- android - 在节点js服务器android上上传图像(多部分数据)
- python - 在Python中生成具有三个不同长度字母的随机字符串
- javascript - 鼠标移出时滚动回框的顶部
- unity3d - 这是从复杂到复杂的 FFT 还是错误?
- android - 将 LiveData 数据绑定到 CustomView
- algorithm - 将文本消息拆分为 30 个字符的块,后缀为 (k/n)
- c# - 缺少 RelationalTypeMapping 实体框架核心
- javascript - 字符串到数字的转换无法在 javascript 中给出预期的结果
- javascript - 使用 for 循环和函数的 JavaScript 问题
- hyperledger - Composer 休息服务器实体太大