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

Publishing Headers are unable to store Table with slice values #125

Closed
jkbmdk opened this issue Oct 7, 2022 · 4 comments
Closed

Publishing Headers are unable to store Table with slice values #125

jkbmdk opened this issue Oct 7, 2022 · 4 comments

Comments

@jkbmdk
Copy link

jkbmdk commented Oct 7, 2022

I'm trying to publish message similar to:

channel.PublishWithContext(
        ctx,
        exchange,
        messageName,
        false,
        false,
        amqp091.Publishing{
            ContentType:  "application/json",
            ContentEncoding: "utf-8",
            Body:  payload,
            Headers: amqp091.Table{"_trace": []string{"a", "b"}},
        }
)

and i receive error
table field "_trace" value []string not supported
I guess problem lies on slice validation https://github.com/streadway/amqp/blob/master/types.go#L232, shouldn't it be done using reflect?
Passing strings vector is not a problem via PHP amqp lib, so it seems to me that this is not the limitation of a rabbitmq.

I'm using

  • go version 1.18.1
  • amqp091-go v1.5.0
@lukebakken
Copy link
Contributor

Passing strings vector is not a problem via PHP amqp lib

My guess is that the PHP library is able to serialize the data for you. It would be interesting to see what you are doing, so please provide some code I can run to see how this works in PHP.

In your case you should serialize []string{"a", "b"} to a string or binary value, and use that as the value for _trace - https://github.com/rabbitmq/amqp091-go/blob/main/types.go#L210-L230

@jkbmdk
Copy link
Author

jkbmdk commented Oct 10, 2022

Sending an unserialized vector is probably build-in rabbit feature. I have not found any serialization in PHP lib and also you are able to publish list using rabbit gui:
image
and that's the way rabbit displays message with list in header
image
also comment in https://github.com/streadway/amqp/blob/master/types.go#L213 suggests that you should be able to pass e.g. []string to header value. Today I'll try to create pull request with a fix proposal

@Zerpet
Copy link
Contributor

Zerpet commented Oct 10, 2022

I'm not sure we claim to have support for []string values, based on https://pkg.go.dev/github.com/rabbitmq/amqp091-go#Table

I'm happy to review a PR to add support for lists of supported AMQP types.

@jkbmdk
Copy link
Author

jkbmdk commented Oct 11, 2022

That was my fault, I've misunderstood some concepts and I'm able to pass _trace like this

channel.PublishWithContext(
        ctx,
        exchange,
        messageName,
        false,
        false,
        amqp091.Publishing{
            ContentType:  "application/json",
            ContentEncoding: "utf-8",
            Body:  payload,
            Headers: amqp091.Table{"_trace": []interface{}{"a", "b"}},
        }
)

@jkbmdk jkbmdk closed this as completed Oct 11, 2022
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

3 participants