github.com/wfusion/gofusion@v1.1.14/common/infra/watermill/UPGRADE-0.4.md (about) 1 # UPGRADE FROM 0.3.x to 0.4 2 3 ## `watermill/components/cqrs` 4 5 ### `CommandHandler.HandlerName` and `EventHandler.HandlerName` was added to the interface. 6 7 If you are using metrics component, you may want to keep backward capability with handler names. In other cases, you can implement your own method of generating handler name. 8 9 Keeping backward capability for **event handlers**: 10 11 ``` 12 func (h CommandHandler) HandlerName() string { 13 return fmt.Sprintf("command_processor-%s", h) 14 } 15 ``` 16 17 Keeping backward capability for **command handlers**: 18 19 ``` 20 func (h EventHandler) HandlerName() string { 21 return fmt.Sprintf("event_processor-%s", ObjectName(h)) 22 } 23 ``` 24 25 ### Added `CommandsSubscriberConstructor` and `EventsSubscriberConstructor` 26 27 From now on, `CommandsSubscriberConstructor` and `EventsSubscriberConstructor` are passed to constructors in CQRS component. 28 29 They allow creating customized subscribers for every handler. For usage examples please check [_examples/cqrs-protobuf](_examples/cqrs-protobuf). 30 31 32 ### Added context to `CommandHandler.Handle`, `CommandBus.Send`, `EventHandler.Handle` and `EventBus.Send` 33 34 Added missing context, which is passed to Publish function and handlers. 35 36 ### Other 37 38 - `NewCommandProcessor` and `NewEventProcessor` now return an error instead of panic 39 - `DuplicateCommandHandlerError` is returned instead of panic when two handlers are handling the same command 40 - `CommandProcessor.routerHandlerFunc` and `EventProcessor.routerHandlerFunc` are now private 41 - using `GenerateCommandsTopic` and `GenerateEventsTopic` functions instead of constant topic to allow more flexibility 42 43 44 ## `watermill/message/infrastructure/amqp` 45 46 ### `Config.QueueBindConfig.RoutingKey` was replaced with `GenerateRoutingKey` 47 48 For backward compatibility, when using the constant value you should use a function: 49 50 51 ``` 52 func(topic string) string { 53 return "routing_key" 54 } 55 ``` 56 57 58 ## `message/router/middleware` 59 60 - `PoisonQueue` is now `PoisonQueue(pub message.Publisher, topic string) (message.HandlerMiddleware, error)`, not a struct 61 62 63 ## `message/router.go` 64 65 - From now on, when all handlers are stopped, the router will also stop (`TestRouter_stop_when_all_handlers_stopped` test)