Skip to content

Commit

Permalink
Add option for controlling reponse from CapHeader. #1541
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Jun 10, 2024
1 parent bce8dc7 commit 1cd3f40
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/DotNetCore.CAP/Internal/ISubscribeInvoker.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ public async Task<ConsumerExecutedResult> InvokeAsync(ConsumerContext context,
var message = context.DeliverMessage;
var parameterDescriptors = context.ConsumerDescriptor.Parameters;
var executeParameters = new object?[parameterDescriptors.Count];
var headerIndex = 0;
for (var i = 0; i < parameterDescriptors.Count; i++)
{
var parameterDescriptor = parameterDescriptors[i];
if (parameterDescriptor.IsFromCap)
{
executeParameters[i] = GetCapProvidedParameter(parameterDescriptor, message, cancellationToken);
headerIndex = i;
}
else
{
if (message.Value != null)
{
// use ISerializer when reading from storage, skip other objects if not Json
if (_serializer.IsJsonType(message.Value))
if (_serializer.IsJsonType(message.Value))
{
executeParameters[i] =
_serializer.Deserialize(message.Value, parameterDescriptor.ParameterType);
Expand Down Expand Up @@ -125,7 +123,16 @@ public async Task<ConsumerExecutedResult> InvokeAsync(ConsumerContext context,
}
}

return new ConsumerExecutedResult(resultObj, message.GetId(), message.GetCallbackName(), (executeParameters[headerIndex] as CapHeader)?.ResponseHeader);
var callbackName = message.GetCallbackName();
if (string.IsNullOrEmpty(callbackName))
{
return new ConsumerExecutedResult(resultObj, message.GetId(), null, null);
}
else
{
var capHeader = executeParameters.FirstOrDefault(x => x is CapHeader) as CapHeader;
return new ConsumerExecutedResult(resultObj, message.GetId(), callbackName, capHeader?.ResponseHeader);
}
}

private static object GetCapProvidedParameter(ParameterDescriptor parameterDescriptor, Message message,
Expand Down

0 comments on commit 1cd3f40

Please sign in to comment.