Skip to content

Commit

Permalink
Merge pull request #2 from vseinstrumentiru/message_id-string
Browse files Browse the repository at this point in the history
fix: message id to string
  • Loading branch information
tioffs authored May 20, 2022
2 parents ce6810c + 2e4753b commit f352699
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43
version: v1.42
24 changes: 8 additions & 16 deletions handler.kafka.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// Code generated by protoc-gen-go-kafka. DO NOT EDIT.
//
// versions:
// protoc-gen-go v1.27.1
// protoc-gen-go-kafka {{.Version}}
// protoc (unknown)
// source: {{.PathFile}}

Expand All @@ -11,23 +11,22 @@ import (
"context"

"github.com/ThreeDotsLabs/watermill/message"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"google.golang.org/protobuf/encoding/protojson"
)

// {{.ModelName}}Event структурая, содержащая поля сообщения
type {{.ModelName}}Event struct {
ID uuid.UUID
ID string
Meta map[string]string
Body *{{.ModelName}}
}

// New{{.ModelName}}Event конструктор события {{.ModelName}}Event
func New{{.ModelName}}Event(data *{{.ModelName}}) *{{.ModelName}}Event {
func New{{.ModelName}}Event(id string, data *{{.ModelName}}) *{{.ModelName}}Event {
return &{{.ModelName}}Event{
ID: uuid.New(),
ID: id,
Meta: make(map[string]string),
Body: data,
}
Expand Down Expand Up @@ -62,20 +61,13 @@ func Make{{.ModelName}}Handler(handler {{.ModelName}}Handler) message.NoPublishH
return nil
}

id, err := uuid.Parse(msg.UUID)
if err != nil {
log.Err(err).Msg("невозможно разобрать идентификатор сообщения")

return nil
}

evt := &{{.ModelName}}Event{
ID: id,
ID: msg.UUID,
Meta: msg.Metadata,
Body: r,
}

if err = handler.Handle(msg.Context(), evt); err != nil {
if err := handler.Handle(msg.Context(), evt); err != nil {
return errors.Wrap(err, "не удалось обработать событие")
}

Expand Down Expand Up @@ -103,7 +95,7 @@ func (r *{{.ModelNamePrivate}}Publisher) Publish(event *{{.ModelName}}Event) err
return errors.Wrap(err, "невозможно сериализовать данные")
}

msg := message.NewMessage(event.ID.String(), payload)
msg := message.NewMessage(event.ID, payload)

if event.Meta == nil {
event.Meta = map[string]string{}
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ type gen struct {
ModelName string
PackageName string
PathFile string
Version string
}

const (
defaultSuffix = "Export"
version = "v1.1.1"
version = "v1.1.3"
)

func main() {
Expand Down Expand Up @@ -53,6 +54,7 @@ func main() {
ModelName: message.GetName(),
PackageName: string(file.GoPackageName),
PathFile: file.Desc.Path(),
Version: version,
})
if err != nil {
plugin.Error(err)
Expand Down

0 comments on commit f352699

Please sign in to comment.