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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Implement message headers #338

wants to merge 3 commits into from

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)

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

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.

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
2 participants