Skip to content
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

feature: Support the Subject property when publishing to SNS #3270

Merged
merged 8 commits into from
Aug 27, 2024

Conversation

jtsalva
Copy link
Contributor

@jtsalva jtsalva commented Aug 21, 2024

Use Message.Header.Subject as SNS subject

/// <summary>
/// The optional Subject passed through to the published SNS message
/// </summary>
public Func<Message, string> SnsSubject { get; set; } = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming here suggests that this is actual value for the subject, rather than something that generates subjects for a given message. I would suggest something like SnsSubjectGenerator, with a description of "An optional delegate for generating the SNS subject for a given message".

@jtsalva jtsalva changed the title feature: Support the Subject property on SNS events feature: Support the Subject property when publishing to SNS Aug 23, 2024
@jtsalva jtsalva marked this pull request as ready for review August 23, 2024 11:13
jtsalva added a commit to jtsalva/Brighter that referenced this pull request Aug 23, 2024
@jtsalva jtsalva mentioned this pull request Aug 23, 2024
Copy link
Member

@iancooper iancooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions here.

Typically we compose the body of a message from the properties of the request that is being serialized. We don't tend to add metadata in via the publish process, but via that message mapping pipeline (either the sink or intermediary middleware).

The publication is accessible via middleware, so it might make sense to add a subject, particularly if we are adding metadata into the body of the message, via that middleware and not via the serialization of the request in the sink. This allows you to not have to remember to add in subject in every mapper, just add the middleware (especially as V10 wants to add default mappers).

As subject is meant for an email header, it would feel that you are doing something specific here i.e. composing a message that will be sent as an email, so adding middleware that supports an SNS subject may be the right approach.

We may need to think about our goal here. I am not sure this is the right approach. I can see why you would opt for it, without knowing about the mapping pipeline however. So I do get that.

@jtsalva
Copy link
Contributor Author

jtsalva commented Aug 27, 2024

Summary of chat with @iancooper

Ideally, Brighter would avoid this work because the SNS Subject is intended for email and is arguably being misused by JustSaying. Nevertheless we agreed on the following:

  • Message.Subject, currently only used for cloud events will be reused to carry the SNS subject in v10. In v9, the SNS subject will be contained in the message bag. The message producer will pass any provided subject onto SNS and the consumer will make available the SNS subject in Message
  • Brighter library users are recommended to use tranformers to map the subject from and to Message but also have the option of just doing that in the mapper

@jtsalva jtsalva marked this pull request as draft August 27, 2024 14:53
@jtsalva jtsalva marked this pull request as ready for review August 27, 2024 15:44
@@ -45,7 +45,7 @@ public SqsMessagePublisher(string topicArn, AmazonSimpleNotificationServiceClien
public string Publish(Message message)
{
var messageString = message.Body.Value;
var publishRequest = new PublishRequest(_topicArn, messageString);
var publishRequest = new PublishRequest(_topicArn, messageString, message.Header.Subject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what happens if the subject is null or empty? We probably need a test for that, as modifying the existing test won't tell us if it is breaking for existing consumers. It just needs a conditional if it breaks anyone.


public SqsMessageProducerSendTests()
{
_myCommand = new MyCommand{Value = "Test"};
_myCommand = new MyCommand{Value = "Testttttttt"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, we need a test for when there is no subject.

@jtsalva jtsalva force-pushed the feature-add-subject branch from 9fa04ea to b53a1ae Compare August 27, 2024 16:11
@iancooper
Copy link
Member

@jtsalva merged

@iancooper iancooper merged commit 1234f63 into BrighterCommand:master Aug 27, 2024
17 of 19 checks passed
@jtsalva jtsalva deleted the feature-add-subject branch August 27, 2024 17:35
iancooper pushed a commit that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants