Code: Select all
public record AddContextMessage
{
public required string Host { get; init; } = string.Empty;
public required CaseContextDto CaseContext { get; init; }
}
< /code>
Ich habe sichergestellt, dass der Namespace an beiden Enden übereinstimmt.public class AddContextConsumer : IConsumer
{
// Some services and ctor redacted for brevity
public Task Consume(ConsumeContext message)
{
var dto = message.Message.CaseContext;
_service.DoStuff(dto);
return Task.CompletedTask;
}
}
< /code>
Mein Verlag ist auch ziemlich einfach, obwohl wir aufgrund einiger schlechter DI -Auswahl zuvor manuell einen Bereich erstellen mussten. < /p>
public async Task PublishAsync(T message)
{
var messageType = message.GetType().Name;
try
{
_logger.LogInformation("Preparing to publish {MessageType}", messageType);
using (var scope = _scopeFactory.CreateScope())
{
var publishEndpoint = scope.ServiceProvider.GetRequiredService();
await publishEndpoint.Publish(message);
}
_logger.LogInformation("Successfully published {MessageType}", messageType);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to publish message of type {MessageType}", messageType);
throw;
}
}
Ich bekomme ein paar dieser Fehler in den Lokalstackprotokollen: < /p>
Code: Select all
2025-02-27 16:15:57 2025-02-27T16:15:57.358 INFO --- [et.reactor-9] localstack.request.aws : AWS sqs.ReceiveMessage => 200
2025-02-27 16:15:58 2025-02-27T16:15:58.386 ERROR --- [et.reactor-6] l.aws.handlers.logging : exception during call chain: object of type 'NoneType' has no len()
2025-02-27 16:15:58 2025-02-27T16:15:58.386 INFO --- [et.reactor-6] localstack.request.aws : AWS sns.PublishBatch => 500 (InternalError)
2025-02-27 16:15:58 2025-02-27T16:15:58.387 ERROR --- [et.reactor-4] l.aws.handlers.logging : exception during call chain: object of type 'NoneType' has no len()
2025-02-27 16:15:58 2025-02-27T16:15:58.388 INFO --- [et.reactor-4] localstack.request.aws : AWS sns.PublishBatch => 500 (InternalError)
2025-02-27 16:15:58 2025-02-27T16:15:58.392 ERROR --- [et.reactor-5] l.aws.handlers.logging : exception during call chain: object of type 'NoneType' has no len()
2025-02-27 16:15:58 2025-02-27T16:15:58.393 ERROR --- [et.reactor-2] l.aws.handlers.logging : exception during call chain: object of type 'NoneType' has no len()
2025-02-27 16:15:58 2025-02-27T16:15:58.393 INFO --- [et.reactor-5] localstack.request.aws : AWS sns.PublishBatch => 500 (InternalError)
< /code>
Was könnte dies verursachen?{
"QueueUrls": [
"http://sqs.us-east-1.127.0.0.1:4566/000000000000/add-context"
]
< /code>
und die Abonnements: < /p>
{
"SubscriptionArn": "arn:aws:sns:us-east-1:000000000000:add-context:7f0ab91b-a9d2-484a-918d-6b2f5789be80",
"Owner": "000000000000",
"Protocol": "sqs",
"Endpoint": "arn:aws:sqs:us-east-1:000000000000:add-context",
"TopicArn": "arn:aws:sns:us-east-1:000000000000:add-context"
},
< /code>
Nach einigen Änderungen kann ich jetzt erfolgreich andere einfachere Nachrichten veröffentlichen und konsumieren: < /p>
public class AddRedirectsMessage
{
public required string Host { get; init; }
public required HashSet Redirects { get; init; }
}
x.UsingAmazonSqs(
(context, cfg) =>
{
var settings = context.GetRequiredService().SystemTextSettings;
cfg.ConfigureJsonSerializerOptions(options =>
{
foreach (var converter in settings.Converters)
{
options.Converters.Add(converter);
}
return options;
});
var configuration = context.GetRequiredService();
var regionEndpoint = AwsCredentials.GetRegionEndpoint(configuration.GetDeployment());
cfg.Host(
regionEndpoint.SystemName,
h =>
{
if (configuration.IsDeployed())
{
h.Credentials(AwsCredentials.GetCredentials(configuration));
}
else
{
// redirect to localstack - need to configure this really
h.AccessKey("dummy"); // LocalStack accepts any non-empty credentials
h.SecretKey("dummy");
h.Config(new AmazonSQSConfig { ServiceURL = "http://localhost:4566" });
h.Config(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localhost:4566" });
}
// specify a scope for all queues
h.Scope(configuration.GetDeploymentName());
// scope topics as well
h.EnableScopedTopics();
}
);
busConfig?.Invoke(cfg, context);
}
);
< /code>
Debugging in den Masstransit -Code.>