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

feat: Add support Message attributes #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {check} from 'k6';
import { check } from 'k6';
import pubsub from 'k6/x/pubsub';

export default function () {
Expand All @@ -15,7 +15,7 @@ export default function () {
trace: true,
doNotCreateTopicIfMissing: false
});
let error = pubsub.publish(client, 'topic_name', 'message data');
let error = pubsub.publish(client, 'topic_name', 'message data', {key:"value",key2:"value2"});

check(error, {
"is sent": err => err === null
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/ThreeDotsLabs/watermill-googlecloud v1.0.6
github.com/mitchellh/mapstructure v1.1.2
go.k6.io/k6 v0.32.0
google.golang.org/api v0.30.0
)
6 changes: 4 additions & 2 deletions pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (ps *PubSub) Publisher(config map[string]interface{}) *googlecloud.Publishe
// Publish publishes a message to the provided topic using provided
// googlecloud.Publisher. The msg value must be passed as string
// and will be converted to bytes sequence before publishing.
func (ps *PubSub) Publish(ctx context.Context, p *googlecloud.Publisher, topic, msg string) error {
func (ps *PubSub) Publish(ctx context.Context, p *googlecloud.Publisher, topic, msg string, attributes map[string]string) error {
state := lib.GetState(ctx)

if state == nil {
Expand All @@ -85,9 +85,11 @@ func (ps *PubSub) Publish(ctx context.Context, p *googlecloud.Publisher, topic,
return err
}

m := message.NewMessage(watermill.NewShortUUID(), []byte(msg))
m.Metadata = attributes
err := p.Publish(
topic,
message.NewMessage(watermill.NewShortUUID(), []byte(msg)),
m,
)

if err != nil {
Expand Down