add support for publish API
Sauci opened this issue · comments
Guillaume Sottas commented
Hello, it would be great to support the /api/exchanges/vhost/name/publish
API. I would propose something like this:
package rabbithole
import (
"encoding/json"
"net/http"
"net/url"
)
type PublishInfo struct {
Properties *Properties `json:"properties"`
RoutingKey string `json:"routing_key"`
Payload string `json:"payload"`
PayloadEncoding string `json:"payload_encoding"`
}
func (c *Client) PostPublish(vhostname string, exchange string, message PublishInfo) (res *http.Response, err error) {
body, err := json.Marshal(message)
if err != nil {
return nil, err
}
req, err := newRequestWithBody(c, "POST", "exchanges/"+url.PathEscape(vhostname)+"/"+exchange+"/publish", body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}
Please let me know what you think about it, and I will send a pull request once the API provided by this package will be well defined.
Michael Klishin commented
Duplicate of #161. I won't accept this contribution, sorry. Thank you for taking the time.