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

Allow to specify the MessageAttributes when publishing an event #131

Open
alessandrozucca opened this issue Dec 19, 2017 · 6 comments
Open

Comments

@alessandrozucca
Copy link
Contributor

In order to be able to use the attribute based filtering, would be nice if the Publisher allowed to specify the MessageAttributes field in sns.PublishInput so basically have something like:

// PublishRaw will emit the byte array to the SNS topic.
// The key will be used as the SNS message subject.
func (p *publisher) PublishRaw(_ context.Context, key string, m []byte, messageAttributes map[string]*MessageAttributeValue) error {
	msg := &sns.PublishInput{
		TopicArn: &p.topic,
		Subject:  &key,
		Message:  aws.String(base64.StdEncoding.EncodeToString(m)),
		MessageAttributes: messageAttributes,
	}

	_, err := p.sns.Publish(msg)
	return err
}

ref. https://aws.amazon.com/blogs/compute/simplify-pubsub-messaging-with-amazon-sns-message-filtering/

@jprobinson
Copy link
Contributor

Howdy @alessandrozucca!

Sorry for the delay, I've been thinking about this one since you posted.

While it does seem handy, I do worry about this leading to a leaky abstraction as we've been trying to find the lowest common denominator between SNS, Kafka & Google PubSub.

I do see that PubSub also has attributes but I haven't found something similar in the Kafka world so I'm a bit hesitant to alter our main interface.

Perhaps we can make a new Publisher interface (similar to the MultiPublisher) and maybe it just wont be implemented for Kafka?

@alessandrozucca
Copy link
Contributor Author

Hi @jprobinson

Sorry for the delay in the response and happy new year 🎉

I understand your reason for not wanting to change the main interface.

Creating a new Publisher that allows to specify the message attributes makes sense.

In the meanwhile, to get this working, I have already added in a local package an interface (with a third argument map[string]*sns.MessageAttributeValue) and copied your implementation of the publisher allowing the MessageAttibute to be specified.

@coryt
Copy link

coryt commented Apr 18, 2019

I get the reason for not adding it, but I would love to see this added in somehow.
I have taken a similar approach to @alessandrozucca and implemented this in a local package.

@taraspos
Copy link
Contributor

taraspos commented Nov 5, 2019

@jprobinson what if attributes will be passed via context, so there is no need to change the interface and context will be optionally handled?

Something like:

if v, ok := ctx.Value("MessageAttributes").(map[string]*sns.MessageAttributeValue); ok {
      msg.MessageAttributes = v
}

@alessandrozucca-pp
Copy link

Think this issue can be closed - I have just noticed that this has been implemented 😄

@pingsutw
Copy link

@trane9991 is possible to do similar thing for google pub/sub? I want to set attribute for my event which will be sent to google pub/sub

if v, ok := ctx.Value("MessageAttributes").(map[string]*sns.MessageAttributeValue); ok {
      msg.MessageAttributes = v
}

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

No branches or pull requests

6 participants