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

Implement message headers #338

Merged
merged 8 commits into from
Dec 10, 2024
Merged

Implement message headers #338

merged 8 commits into from
Dec 10, 2024

Conversation

v0idpwn
Copy link
Collaborator

@v0idpwn v0idpwn commented Nov 2, 2024

Closes #203
Needed for #294

Implement message headers
@v0idpwn v0idpwn marked this pull request as ready for review November 2, 2024 18:34
Copy link
Contributor

@theory theory left a comment

Choose a reason for hiding this comment

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

Looks straightforward, but please:

  • Add an upgrade script that can upgrade the SQL from the previous version to this version's change. Details here.
  • Add tests for the new functions and behaviors.

Thanks!

@v0idpwn
Copy link
Collaborator Author

v0idpwn commented Nov 4, 2024

Of course, this is an API proposal, not ready yet :)
Sorry, communicated with @ChuckHend but didn't write it in description

@theory
Copy link
Contributor

theory commented Nov 4, 2024

Of course, this is an API proposal, not ready yet :) Sorry, communicated with @ChuckHend but didn't write it in description

Ah, got it, didn't realize, thanks for clarifying.

@theory
Copy link
Contributor

theory commented Nov 4, 2024

(Consider converting this to a Draft PR)

@ChuckHend ChuckHend requested a review from theory November 11, 2024 17:16
Comment on lines +306 to +314
-- send: 4 args with integer delay
CREATE FUNCTION pgmq.send(
queue_name TEXT,
msg JSONB,
headers JSONB,
delay INTEGER
) RETURNS SETOF BIGINT AS $$
SELECT * FROM pgmq.send(queue_name, msg, headers, clock_timestamp() + make_interval(secs => delay));
$$ LANGUAGE sql;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing the variants with just two using defaults:

-- send: 4 args with integer delay
CREATE FUNCTION pgmq.send(
    queue_name TEXT,
    msg JSONB,
    headers JSONB DEFAULT = NULL,
    delay INTEGER DEFAULT = 0
) RETURNS SETOF BIGINT AS $$
    SELECT * FROM pgmq.send(queue_name, msg, headers, clock_timestamp() + make_interval(secs => delay));
$$ LANGUAGE sql;

CREATE FUNCTION pgmq.send(
    queue_name TEXT,
    msg JSONB,
    headers JSONB DEFAULT = NULL,
    delay TIMESTAMP WITH TIME ZONE = clock_timestamp(),
) RETURNS SETOF BIGINT AS $$
    SELECT * FROM pgmq.send(queue_name, msg, headers, delay);
$$ LANGUAGE sql;

Copy link
Collaborator Author

@v0idpwn v0idpwn Nov 11, 2024

Choose a reason for hiding this comment

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

I think it's not equivalent. I'm accepting pgmq.send(queue_name, msg, integer/timestamp) too

Copy link
Member

Choose a reason for hiding this comment

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

@theory, I think your suggestion results in a breaking API change? The 3-argument calls would become ambiguous.

I tried the suggestion locally and then ran tests...

+ERROR:  function pgmq.send(unknown, unknown, jsonb) is not unique
+LINE 1: SELECT * from pgmq.send('test_unlogged_queue', '{"hello": "w...
+                      ^
+HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

If this is the case, I would like hold on the breaking API changes v2.0 release.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense.

SELECT * FROM pgmq.send_batch(queue_name, msgs, NULL, clock_timestamp() + make_interval(secs => delay));
$$ LANGUAGE sql;

-- send batch: 3 args with timestamp
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, try using DEFAULT expressions in parameter lists to reduce the number of variants.

@academiaresf
Copy link

i can help for merging this?

@ChuckHend
Copy link
Member

i can help for merging this?

We do need some tests!

@v0idpwn
Copy link
Collaborator Author

v0idpwn commented Dec 7, 2024

I think it's complete now

END;
$$ LANGUAGE plpgsql;

-- Update existing queues
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@ChuckHend ChuckHend left a comment

Choose a reason for hiding this comment

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

✅ I tested locally, including upgrading from v1.4.5 and did not see any issues.

@theory requested changes though, so would like to give him a chance to respond before merging.

@v0idpwn v0idpwn merged commit f5c04a4 into main Dec 10, 2024
19 checks passed
@v0idpwn v0idpwn deleted the feat/headers branch December 10, 2024 17:19
waitingsong added a commit to waitingsong/pgmq-js that referenced this pull request Jan 9, 2025
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.

Feature request: support headers, like ActiveMQ
4 participants