From 178d68aae946b07ad0c016e6681cbb8aedd3c9fb Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 18:46:00 +0300 Subject: [PATCH 1/2] add message metadata support Signed-off-by: Vasiliy Tolstov --- http.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/http.go b/http.go index 8e843df..b29468a 100644 --- a/http.go +++ b/http.go @@ -604,6 +604,8 @@ func (h *httpClient) Publish(ctx context.Context, p client.Message, opts ...clie } func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...client.PublishOption) error { + var body []byte + options := client.NewPublishOptions(opts...) // get proxy @@ -622,24 +624,22 @@ func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...c for _, p := range ps { md := metadata.Copy(omd) md[metadata.HeaderContentType] = p.ContentType() - md[metadata.HeaderTopic] = p.Topic() - - cf, err := h.newCodec(p.ContentType()) - if err != nil { - return errors.InternalServerError("go.micro.client", err.Error()) - } - - var body []byte // passed in raw data if d, ok := p.Payload().(*codec.Frame); ok { body = d.Data } else { - b := bytes.NewBuffer(nil) - if err := cf.Write(b, &codec.Message{Type: codec.Event}, p.Payload()); err != nil { + // use codec for payload + cf, err := h.newCodec(p.ContentType()) + if err != nil { return errors.InternalServerError("go.micro.client", err.Error()) } - body = b.Bytes() + // set the body + b, err := cf.Marshal(p.Payload()) + if err != nil { + return errors.InternalServerError("go.micro.client", err.Error()) + } + body = b } topic := p.Topic() @@ -647,6 +647,9 @@ func (h *httpClient) publish(ctx context.Context, ps []client.Message, opts ...c topic = exchange } + for k, v := range p.Metadata() { + md.Set(k, v) + } md.Set(metadata.HeaderTopic, topic) msgs = append(msgs, &broker.Message{Header: md, Body: body}) } -- 2.45.2 From 2e218748e860092013882b20e8aa95e0a87f5e0c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 5 Mar 2022 18:47:38 +0300 Subject: [PATCH 2/2] fix workflow Signed-off-by: Vasiliy Tolstov --- .github/workflows/autoapprove.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/autoapprove.yml b/.github/workflows/autoapprove.yml index 3d8e3fe..3e0ffed 100644 --- a/.github/workflows/autoapprove.yml +++ b/.github/workflows/autoapprove.yml @@ -16,6 +16,5 @@ jobs: uses: hmarr/auto-approve-action@v2 if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]' id: approve - env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.TOKEN}} + with: + github-token: ${{secrets.TOKEN}} \ No newline at end of file -- 2.45.2