-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compression and JustSaying 8.0 Changes #1525
base: main
Are you sure you want to change the base?
Conversation
var serializerFactory = p.GetRequiredService<IMessageSerializationFactory>(); | ||
return new MessageSerializationRegister(config.MessageSubjectProvider, serializerFactory); | ||
}); | ||
services.TryAddSingleton((p) => new MessageCompressionRegistry([new GzipMessageBodyCompression()])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we resolved all the compressions from DI and then just registered GZip as the only one?
}) | ||
.Singleton(); | ||
|
||
For<MessageCompressionRegistry>().Use((p) => new MessageCompressionRegistry(new List<IMessageBodyCompression> { new GzipMessageBodyCompression() })).Singleton(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
src/JustSaying/AwsTools/MessageHandling/Compression/PublishCompressionOptions.cs
Show resolved
Hide resolved
/// Gets or sets the compression encoding to be used. | ||
/// </summary> | ||
/// <remarks> | ||
/// This should correspond to a registered compression algorithm in the IMessageCompressionRegistry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This should correspond to a registered compression algorithm in the IMessageCompressionRegistry. | |
/// This should correspond to a registered compression algorithm in the <see cref="IMessageCompressionRegistry"/>. |
@@ -8,21 +8,18 @@ | |||
|
|||
namespace JustSaying.AwsTools.MessageHandling.Dispatch; | |||
|
|||
public class MessageDispatcher : IMessageDispatcher | |||
internal class MessageDispatcher : IMessageDispatcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we seal it now if it's internal?
/// <summary> | ||
/// Gets all available attribute keys. | ||
/// </summary> | ||
/// <returns>An IReadOnlyCollection of strings representing all attribute keys.</returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <returns>An IReadOnlyCollection of strings representing all attribute keys.</returns> | |
/// <returns>An <see cref="IReadOnlyCollection{T}"/> of strings representing all attribute keys.</returns> |
} | ||
|
||
public IMessageSerializer GetSerializer<T>() where T : Message => _serializer; | ||
public IMessageBodySerializer GetSerializer<T>() where T : Message => new NewtonsoftMessageBodySerializer<T>(settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want/need to create a new instance every time?
} | ||
} | ||
|
||
public sealed class PublishMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to own file.
src/JustSaying/Messaging/MessageSerialization/SystemTextJsonMessageBodySerializerBase.cs
Outdated
Show resolved
Hide resolved
public string Serialize(Message message) | ||
{ | ||
return JsonSerializer.Serialize(message, message.GetType(), _options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this Serialize<T>(T message)
? message.GetType()
won't play friendly for native AoT if we add support for that in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine we may not have generic type in all callers. For AoT we can create and store the JTI if available in the constructor (and throw if not available), and use in the serialize and deserialize methods.
/// <summary> | ||
/// Initializes a new instance of the <see cref="SystemTextJsonMessageBodySerializer{T}"/> class with default JSON serializer options. | ||
/// </summary> | ||
public SystemTextJsonMessageBodySerializer() | ||
{ | ||
_options = DefaultJsonSerializerOptions; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to say we should drop this constructor in favour of exposing a default options that can be passed to the other constructor. In AoT this one will have to be an instant throw.
src/JustSaying/AwsTools/MessageHandling/IPublishMessageConverter.cs
Outdated
Show resolved
Hide resolved
src/JustSaying/Messaging/MessageSerialization/SystemTextJsonMessageBodySerializer.cs
Outdated
Show resolved
Hide resolved
@@ -30,12 +30,12 @@ public ReceivedMessage ConvertForReceive(Amazon.SQS.Model.Message message) | |||
var jsonNode = JsonNode.Parse(body); | |||
if (jsonNode is JsonObject jsonObject && jsonObject.TryGetPropertyValue("Message", out var messageNode)) | |||
{ | |||
body = messageNode.ToString(); | |||
body = messageNode?.ToString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be ToJsonString()
?
_queue = CreateSuccessfulTestQueue(Guid.NewGuid().ToString(), | ||
new TestMessage | ||
{ | ||
Body = $$"""{"Subject":"SimpleMessage", "Message": "{{JsonEncodedText.Encode("""{ "Content": "Hi" }""")}}"}""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL JsonEncodedText
.
There is still more to go, but I'm pushing this now to get some feedback.
This PR makes the following changes:
Subject
Subject
Outstanding actions: